2014-05-14 35 views
0

Mongo雖然在傳統座標上提供了2dsphere索引,但查詢需要以geoJSON格式呈現給Point/Shapes。例如,我插入了以下記錄來解決收集問題。spring mongo支持geoJSOn for 2dsphere索引

{ "city" : "First", "geo" : [ 13.45, 23.46 ] } 
{ "city" : "Second", "geo" : [ 13.45, 20.46 ] } 

然後我使用下面的命令作爲mongodb的仍允許在舊座標2dsphere索引加入2dsphere索引。

db.address.ensureIndex({"geo":"2dsphere"}) 

然後,如果我使用傳統格式做近$查詢,但得到一個異常。

> 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格式的轉換器。有什麼解決方法嗎?

回答

相關問題