Javascript Mongo GeoJSON:应为位置对象
我正在尝试将GeoJSON对象简单插入Mongo数据库:Javascript Mongo GeoJSON:应为位置对象,javascript,json,node.js,mongodb,database,Javascript,Json,Node.js,Mongodb,Database,我正在尝试将GeoJSON对象简单插入Mongo数据库: > db.users.ensureIndex({'loc': '2d'}) > db.users.insert({'loc': {'type': 'Point', 'coordinates': [50, 50]}}) location object expected, location array not in correct format 没有外部上下文-这是mongo shell中的一个新数据库和一个新集合。我做错了什么
> db.users.ensureIndex({'loc': '2d'})
> db.users.insert({'loc': {'type': 'Point', 'coordinates': [50, 50]}})
location object expected, location array not in correct format
没有外部上下文-这是mongo shell中的一个新数据库和一个新集合。我做错了什么?
表示应该使用2dsphere来使用GeoJSON
db.users.ensureIndex({'loc': '2dsphere'})
你用的是老办法
db.users.ensureIndex({'loc': '2d'})
你必须使用
db.users.insert({'loc': [50.0, 50.0]})
您使用的是哪个版本的mongodb?我相信GeoJSON是在2.4+中,在2.2中你可能需要做db.users.insert({loc':[50.0,50.0]})不是GeoJSON对象的正确用法,更像是{loc':{“type”:“Point”,“coordinates”:[51.88358205555556,-176.64247991667]}