Я хотел бы найти ближайший магазин. Так что я написал этот код:Весенние данные Mongodb Near Query not works
public class ShopRepositoryImpl extends GenericRepositoryImpl<ShopEntity, String> implements ShopRepositoryCustom {
@Autowired
protected MongoTemplate template;
@Override
public GeoResult<ShopEntity> findNearest(Point location) {
List<GeoResult<ShopEntity>> result = template.geoNear(
NearQuery.near(location).maxDistance(new Distance(70, Metrics.KILOMETERS))
.query(new Query(Criteria.where("location")).limit(1)),
ShopEntity.class).getContent();
if (result.isEmpty()) {
return null;
} else {
return result.get(0);
}
}
}
В TOMCAT консоли есть:
2016-01-17 12:13:26.151 WARN 645 --- [nio-8080-exec-2] o.s.data.mongodb.core.MongoTemplate : Command execution of
{ "geoNear" : "shop" , "query" : { "location" : { }} , "maxDistance" : 0.010974991600211786 , "distanceMultiplier" : 6378.137 , "num" : 1 , "near" : [ 48.8703939 , 2.0] , "spherical" : true}
failed: no geo indices for geoNear
И я попытался это:
public interface ShopRepository extends GenericRepository<ShopEntity, String>, ShopRepositoryCustom {
GeoResults<ShopEntity> findByLocationNear(Point location, Distance distance);
}
Нет результата
В моей базе данных у меня есть один элемент:
{
"name": "A shop",
"street": "149 Rue Montmartre",
"city": "Paris",
"zip": "75002",
"country": "France",
"location": {
"x": 48.8703937,
"y": 2.3422999
}
}
моей сущности есть: @GeoSpatialIndexed частного двойное [] местоположения; – Maryo