Search in sources :

Example 1 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class MongoOperationsUnitTests method geoNearRejectsNullEntityClassIfCollectionGiven.

// 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");
        }
    }.assertDataAccessException();
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Point(org.springframework.data.geo.Point) Test(org.junit.Test)

Example 2 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class MongoOperationsUnitTests method geoNearRejectsNullEntityClass.

// 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);
        }
    }.assertDataAccessException();
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Point(org.springframework.data.geo.Point) Test(org.junit.Test)

Example 3 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class AbstractGeoSpatialTests method geoNear.

@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));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Venue(org.springframework.data.mongodb.core.Venue) Metric(org.springframework.data.geo.Metric) Test(org.junit.Test)

Example 4 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class GeoSpatial2DSphereTests method geoNearWithMinDistance.

// DATAMONGO-1110
@Test
public void geoNearWithMinDistance() {
    NearQuery geoNear = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).minDistance(1);
    GeoResults<Venue> result = template.geoNear(geoNear, Venue.class);
    assertThat(result.getContent().size(), is(not(0)));
    assertThat(result.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Venue(org.springframework.data.mongodb.core.Venue) Metric(org.springframework.data.geo.Metric) Test(org.junit.Test)

Example 5 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateTests method geoNear.

// DATAMONGO-1444
@Test
public void geoNear() {
    List<Venue> venues = // 
    Arrays.asList(// 
    new Venue("Penn Station", -73.99408, 40.75057), // 
    new Venue("10gen Office", -73.99171, 40.738868), // 
    new Venue("Flatiron Building", -73.988135, 40.741404), new Venue("Maplewood, NJ", -74.2713, 40.73137));
    StepVerifier.create(template.insertAll(venues)).expectNextCount(4).verifyComplete();
    IndexOperationsAdapter.blocking(template.indexOps(Venue.class)).ensureIndex(new GeospatialIndex("location").typed(GeoSpatialIndexType.GEO_2D));
    NearQuery geoFar = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).maxDistance(150, Metrics.KILOMETERS);
    // 
    StepVerifier.create(template.geoNear(geoFar, Venue.class)).expectNextCount(// 
    4).verifyComplete();
    NearQuery geoNear = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).maxDistance(120, Metrics.KILOMETERS);
    // 
    StepVerifier.create(template.geoNear(geoNear, Venue.class)).expectNextCount(// 
    3).verifyComplete();
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) GeospatialIndex(org.springframework.data.mongodb.core.index.GeospatialIndex) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)14 Document (org.bson.Document)6 Point (org.springframework.data.geo.Point)6 Metric (org.springframework.data.geo.Metric)3 Venue (org.springframework.data.mongodb.core.Venue)3 Method (java.lang.reflect.Method)2 GeospatialIndex (org.springframework.data.mongodb.core.index.GeospatialIndex)2 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)2 Query (org.springframework.data.mongodb.core.query.Query)2 Person (org.springframework.data.mongodb.repository.Person)2 GeoNearExecution (org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution)2 ReadPreference (com.mongodb.ReadPreference)1 Distance (org.springframework.data.geo.Distance)1 AutogenerateableId (org.springframework.data.mongodb.core.MongoTemplateUnitTests.AutogenerateableId)1 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)1