|
|
|
@ -328,7 +328,7 @@ The following example shows how to define a `near` query that finds all persons |
|
|
|
==== |
|
|
|
==== |
|
|
|
[source,java] |
|
|
|
[source,java] |
|
|
|
---- |
|
|
|
---- |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> { |
|
|
|
|
|
|
|
|
|
|
|
// { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance}} |
|
|
|
// { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance}} |
|
|
|
List<Person> findByLocationNear(Point location, Distance distance); |
|
|
|
List<Person> findByLocationNear(Point location, Distance distance); |
|
|
|
@ -361,7 +361,7 @@ Spring Data MongoDb supports geo-near queries, as the following example shows: |
|
|
|
|
|
|
|
|
|
|
|
[source,java] |
|
|
|
[source,java] |
|
|
|
---- |
|
|
|
---- |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> { |
|
|
|
|
|
|
|
|
|
|
|
// {'geoNear' : 'location', 'near' : [x, y] } |
|
|
|
// {'geoNear' : 'location', 'near' : [x, y] } |
|
|
|
GeoResults<Person> findByLocationNear(Point location); |
|
|
|
GeoResults<Person> findByLocationNear(Point location); |
|
|
|
@ -388,7 +388,7 @@ By adding the `org.springframework.data.mongodb.repository.Query` annotation to |
|
|
|
|
|
|
|
|
|
|
|
[source,java] |
|
|
|
[source,java] |
|
|
|
---- |
|
|
|
---- |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> { |
|
|
|
|
|
|
|
|
|
|
|
@Query("{ 'firstname' : ?0 }") |
|
|
|
@Query("{ 'firstname' : ?0 }") |
|
|
|
List<Person> findByThePersonsFirstname(String firstname); |
|
|
|
List<Person> findByThePersonsFirstname(String firstname); |
|
|
|
@ -404,7 +404,7 @@ You can also use the filter property to restrict the set of properties that is m |
|
|
|
|
|
|
|
|
|
|
|
[source,java] |
|
|
|
[source,java] |
|
|
|
---- |
|
|
|
---- |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> { |
|
|
|
|
|
|
|
|
|
|
|
@Query(value="{ 'firstname' : ?0 }", fields="{ 'firstname' : 1, 'lastname' : 1}") |
|
|
|
@Query(value="{ 'firstname' : ?0 }", fields="{ 'firstname' : 1, 'lastname' : 1}") |
|
|
|
List<Person> findByThePersonsFirstname(String firstname); |
|
|
|
List<Person> findByThePersonsFirstname(String firstname); |
|
|
|
@ -455,7 +455,7 @@ to declare the predicate value for `lastname` (which is equivalent to the `?0` p |
|
|
|
|
|
|
|
|
|
|
|
[source,java] |
|
|
|
[source,java] |
|
|
|
---- |
|
|
|
---- |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> { |
|
|
|
|
|
|
|
|
|
|
|
@Query("{'lastname': ?#{[0]} }") |
|
|
|
@Query("{'lastname': ?#{[0]} }") |
|
|
|
List<Person> findByQueryWithExpression(String param0); |
|
|
|
List<Person> findByQueryWithExpression(String param0); |
|
|
|
@ -467,7 +467,7 @@ used in conjunction with JSON reveal a side-effect, because Map-like declaration |
|
|
|
|
|
|
|
|
|
|
|
[source,java] |
|
|
|
[source,java] |
|
|
|
---- |
|
|
|
---- |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> |
|
|
|
public interface PersonRepository extends MongoRepository<Person, String> { |
|
|
|
|
|
|
|
|
|
|
|
@Query("{'id': ?#{ [0] ? {$exists :true} : [1] }}") |
|
|
|
@Query("{'id': ?#{ [0] ? {$exists :true} : [1] }}") |
|
|
|
List<Person> findByQueryWithExpressionAndNestedObject(boolean param0, String param1); |
|
|
|
List<Person> findByQueryWithExpressionAndNestedObject(boolean param0, String param1); |
|
|
|
|