2014-02-11 41 views
1

我試圖做一個以GeoJSON對象的簡單插入操作一個Mongo的數據庫:蒙戈以GeoJSON:位置對象預計

> db.users.ensureIndex({'loc': '2d'}) 
> db.users.insert({'loc': {'type': 'Point', 'coordinates': [50, 50]}}) 
location object expected, location array not in correct format 

沒有外界背景 - 這是一個新的數據庫,並在新的集合蒙戈殼。我究竟做錯了什麼?

+1

什麼的MongoDB版本你是 使用?我相信GeoJSON是2.4+在2.2中,您可能需要做db.users.insert({'loc':[50.0,50.0]}) –

+0

我正在使用2.4.8。 – bitpshr

回答

2

http://docs.mongodb.org/manual/applications/geospatial-indexes/

說,你應該使用2dsphere使用GeoJSON的

db.users.ensureIndex({'loc': '2dsphere'}) 

您使用過的舊方法

db.users.ensureIndex({'loc': '2d'}) 

,你必須使用

db.users.insert({'loc': [50.0, 50.0]}) 
+0

非常感謝。 – bitpshr

+0

是不是要以GeoJSON對象更像'{ 'LOC' 的正確用法:{ 「類型」: 「點」, 「座標」:[ 51.883582055556, -176.64247991667 ] } – ra9r