2014-02-11 45 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