From dadaf374c3c9cbbaa285d8f2801918b004b12e81 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 2 Apr 2014 10:08:41 +0200 Subject: [PATCH] Use manual index declaration in MongoDB sample. --- .../example/springdata/mongodb/customer/Customer.java | 2 -- .../customer/CustomerRepositoryIntegrationTest.java | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mongodb/src/main/java/example/springdata/mongodb/customer/Customer.java b/mongodb/src/main/java/example/springdata/mongodb/customer/Customer.java index 12c44a58..0fac3e4c 100644 --- a/mongodb/src/main/java/example/springdata/mongodb/customer/Customer.java +++ b/mongodb/src/main/java/example/springdata/mongodb/customer/Customer.java @@ -18,7 +18,6 @@ package example.springdata.mongodb.customer; import lombok.Data; import org.bson.types.ObjectId; -import org.springframework.data.mongodb.core.index.GeoSpatialIndexed; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.util.Assert; @@ -34,7 +33,6 @@ public class Customer { private ObjectId id; private String firstname, lastname; - @GeoSpatialIndexed(name = "address.location")// private Address address; /** diff --git a/mongodb/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java b/mongodb/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java index 1efea1ec..8c787efc 100644 --- a/mongodb/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java +++ b/mongodb/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java @@ -28,6 +28,8 @@ import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; +import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.index.GeospatialIndex; import org.springframework.data.querydsl.QSort; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -44,6 +46,7 @@ import example.springdata.mongodb.ApplicationConfiguration; public class CustomerRepositoryIntegrationTest { @Autowired CustomerRepository repository; + @Autowired MongoOperations operations; Customer dave, oliver, carter; @@ -87,6 +90,12 @@ public class CustomerRepositoryIntegrationTest { @Test public void exposesGeoSpatialFunctionality() { + GeospatialIndex indexDefinition = new GeospatialIndex("address.location"); + indexDefinition.getIndexOptions().put("min", -180); + indexDefinition.getIndexOptions().put("max", 180); + + operations.indexOps(Customer.class).ensureIndex(indexDefinition); + Customer ollie = new Customer("Oliver", "Gierke"); ollie.setAddress(new Address(new Point(52.52548, 13.41477))); ollie = repository.save(ollie);