Use manual index declaration in MongoDB sample.

This commit is contained in:
Oliver Gierke
2014-04-02 10:08:41 +02:00
parent 87f91d8afc
commit dadaf374c3
2 changed files with 9 additions and 2 deletions

View File

@@ -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;
/**

View File

@@ -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);