use of org.springframework.data.mongodb.core.index.GeospatialIndex in project spring-data-mongodb by spring-projects.
the class IndexUnitTests method testGeospatialIndex2DSphere.
// DATAMONGO-778
@Test
public void testGeospatialIndex2DSphere() {
GeospatialIndex i = new GeospatialIndex("location").typed(GeoSpatialIndexType.GEO_2DSPHERE);
assertEquals(Document.parse("{ \"location\" : \"2dsphere\"}"), i.getIndexKeys());
assertEquals(Document.parse("{ }"), i.getIndexOptions());
}
use of org.springframework.data.mongodb.core.index.GeospatialIndex in project spring-data-mongodb by spring-projects.
the class IndexUnitTests method testGeospatialIndex.
@Test
public void testGeospatialIndex() {
GeospatialIndex i = new GeospatialIndex("location").withMin(0);
assertEquals(Document.parse("{ \"location\" : \"2d\"}"), i.getIndexKeys());
assertEquals(Document.parse("{ \"min\" : 0}"), i.getIndexOptions());
}
use of org.springframework.data.mongodb.core.index.GeospatialIndex in project spring-data-mongodb by spring-projects.
the class ReactiveFindOperationSupportTests method findAllNearByReturningGeoResultContentAsClosedInterfaceProjection.
// DATAMONGO-1719
@Test
public void findAllNearByReturningGeoResultContentAsClosedInterfaceProjection() {
blocking.indexOps(Planet.class).ensureIndex(new GeospatialIndex("coordinates").typed(GeoSpatialIndexType.GEO_2DSPHERE).named("planet-coordinate-idx"));
Planet alderan = new Planet("alderan", new Point(-73.9836, 40.7538));
Planet dantooine = new Planet("dantooine", new Point(-73.9928, 40.7193));
blocking.save(alderan);
blocking.save(dantooine);
StepVerifier.create(template.query(Planet.class).as(PlanetProjection.class).near(NearQuery.near(-73.9667, 40.78).spherical(true)).all()).consumeNextWith(it -> {
assertThat(it.getDistance()).isNotNull();
assertThat(it.getContent()).isInstanceOf(PlanetProjection.class);
assertThat(it.getContent().getName()).isEqualTo("alderan");
}).expectNextCount(//
1).verifyComplete();
}
use of org.springframework.data.mongodb.core.index.GeospatialIndex in project spring-data-mongodb by spring-projects.
the class ReactiveFindOperationSupportTests method findAllNearBy.
// DATAMONGO-1719
@Test
public void findAllNearBy() {
blocking.indexOps(Planet.class).ensureIndex(new GeospatialIndex("coordinates").typed(GeoSpatialIndexType.GEO_2DSPHERE).named("planet-coordinate-idx"));
Planet alderan = new Planet("alderan", new Point(-73.9836, 40.7538));
Planet dantooine = new Planet("dantooine", new Point(-73.9928, 40.7193));
blocking.save(alderan);
blocking.save(dantooine);
StepVerifier.create(template.query(Planet.class).near(NearQuery.near(-73.9667, 40.78).spherical(true)).all()).consumeNextWith(actual -> {
assertThat(actual.getDistance()).isNotNull();
}).expectNextCount(//
1).verifyComplete();
}
use of org.springframework.data.mongodb.core.index.GeospatialIndex 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