Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mongo GeoJSON:应为位置对象_Javascript_Json_Node.js_Mongodb_Database - Fatal编程技术网

Javascript Mongo GeoJSON:应为位置对象

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中的一个新数据库和一个新集合。我做错了什么

我正在尝试将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中的一个新数据库和一个新集合。我做错了什么?

表示应该使用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]}