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();
}
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();
}
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));
}
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));
}
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();
}
Aggregations