13.07.2015 Views

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

please define productname in your docbook file!Keyword Sample Logical resultBetween findByAgeBetween(int from,int to){"age" : {"$gt" : from,"$lt" : to}}IsNotNull,NotNullfindByFirstnameNotNull(){"age" : {"$ne" : null}}IsNull, Null findByFirstnameNull() {"age" : null}LikeRegexfindByFirstnameLike(Stringname)findByFirstnameRegex(Stringfirstname){"age" : age} ( age as regex){"firstname" : {"$regex" :firstname }}(No keyword) findByFirstname(String name) {"age" : name}NotNearWithinfindByFirstnameNot(Stringname)findByLocationNear(Pointpoint)findByLocationWithin(Circlecircle){"age" : {"$ne" : name}}{"location" : {"$near" :[x,y]}}{"location" : {"$within" :{"$center" : [ [x, y],distance]}}}Within findByLocationWithin(Box box) {"location" : {"$within" :{"$box" : [ [x1, y1], x2,y2]}}}TrueIsTrue, True findByActiveIsTrue() {"active" : true}IsFalse, False findByActiveIsFalse() {"active" : false}ExistsfindByLocationExists(booleanexists){"location" : {"$exists" :exists }}Geo-spatial repository queriesAs you've just seen there are a few keywords triggering geo-spatial operations within a <strong>MongoDB</strong> query.The Near keyword allows some further modification. Let's have look at some examples:public interface PersonRepository extends MongoRepository}// { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance}}List findByLocationNear(Point location, Distance distance);Example 6.7 Advanced Near queriesAdding a Distance parameter to the query method allows restricting results to those within the givendistance. If the Distance was set up containing a Metric we will transparently use $nearSphereinstead of $code.1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 73

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!