Use manual index declaration in MongoDB sample.
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user