Package org.springframework.data.mongodb.core.query

Examples of org.springframework.data.mongodb.core.query.NearQuery


public class GeoNearOperationUnitTests {

  @Test
  public void rendersNearQueryAsAggregationOperation() {

    NearQuery query = NearQuery.near(10.0, 10.0);
    GeoNearOperation operation = new GeoNearOperation(query);
    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);

    DBObject nearClause = DBObjectTestUtils.getAsDBObject(dbObject, "$geoNear");
    assertThat(nearClause, is(query.toDBObject()));
  }
View Full Code Here


    @SuppressWarnings("unchecked")
    private GeoResults<Object> doExecuteQuery(Query query) {

      Point nearLocation = accessor.getGeoNearLocation();
      NearQuery nearQuery = NearQuery.near(nearLocation);

      if (query != null) {
        nearQuery.query(query);
      }

      Distance maxDistance = accessor.getMaxDistance();
      if (maxDistance != null) {
        nearQuery.maxDistance(maxDistance).in(maxDistance.getMetric());
      }

      Pageable pageable = accessor.getPageable();
      if (pageable != null) {
        nearQuery.with(pageable);
      }

      MongoEntityMetadata<?> metadata = method.getEntityInformation();
      return (GeoResults<Object>) operations.geoNear(nearQuery, metadata.getJavaType(), metadata.getCollectionName());
    }
View Full Code Here

  }

  @Test
  public void geoNear() {

    NearQuery geoNear = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).maxDistance(150);

    GeoResults<Venue> result = template.geoNear(geoNear, Venue.class);

    assertThat(result.getContent().size(), is(not(0)));
    assertThat(result.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
View Full Code Here

   * @see DATAMONGO-341
   */
  @Test
  public void geoNearRejectsNullEntityClass() {

    final NearQuery query = NearQuery.near(new Point(10, 20));

    new Execution() {
      @Override
      public void doWith(MongoOperations operations) {
        operations.geoNear(query, null);
View Full Code Here

   * @see DATAMONGO-341
   */
  @Test
  public void geoNearRejectsNullEntityClassIfCollectionGiven() {

    final NearQuery query = NearQuery.near(new Point(10, 20));

    new Execution() {
      @Override
      public void doWith(MongoOperations operations) {
        operations.geoNear(query, null, "collection");
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.query.NearQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.