【发布时间】:2014-05-14 07:20:22
【问题描述】:
Mongo 虽然在旧坐标上提供 2dsphere 索引,但查询需要以 geoJSON 格式呈现给点/形状。例如,我已将以下记录插入到地址集合中。
{ "city" : "First", "geo" : [ 13.45, 23.46 ] }
{ "city" : "Second", "geo" : [ 13.45, 20.46 ] }
然后我使用以下命令添加了 2dsphere 索引,因为 mongodb 仍然允许在旧坐标上使用 2dsphere 索引。
db.address.ensureIndex({"geo":"2dsphere"})
然后,如果我使用旧格式进行 $near 查询,但出现异常。
> db.address.find({"geo":{$near:{"x":13.45,"y":23.45}}})
error: {
"$err" : "can't parse query (2dsphere): { $near: { x: 13.45, y: 23.45 } }",
"code" : 16535
}
但是如果使用 geoJSON 格式进行相同的查询,那么我会得到结果。
> db.address.find({"geo":{$near:{"type":"Point",coordinates:[13.45,23.45]}}})
{ "_id" : ObjectId("537306b4b8ac1f134d9efe89"), "city" : "First", "geo" : [ 13.45, 23.46 ] }
{ "_id" : ObjectId("537306c3b8ac1f134d9efe8a"), "city" : "Second", "geo" : [ 13.45, 20.46 ] }
我的问题是,GeoConverters 已将所有转换都转换为旧格式。所以,如果我使用 2dsphere 索引,它们显然不会工作。是否有任何可用于 geoJSON 格式的转换。有什么解决办法吗?
【问题讨论】:
标签: mongodb spring-data-mongodb