我只是想让一个简单的near
查询起作用。这是我的文档样例。
{"point":
{"type": "Point",
"coordinates": [30.443902444762696, -84.27326978424058]},
"created_on": {"$date": 1398016710168},
"radius": 180,
"user": {"$oid": "53543188eebc5c0cc416b77c"},
"_id": {"$oid": "53544306eebc5c0ecac6cfba"},
"expires_on": {"$date": 1399831110168}
}
我使用mongod并尝试了以下命令:
db.bar.find({point: {$near: [-84.26060492426588, 30.45023887165371]}});
但我得到了这个错误:
错误: { "$err" : "无法执行查询:处理查询时出错:ns=foo.bar skip=0\nTree: GEONEAR field=point maxdist=1.79769e+308 isNearSphere=0 || First: notFirst: full path: point\nSort: {}\nProj: {}\nplanner 返回错误:无法找到 $geoNear 查询的索引", "code" : 17007 }
也许我的搜索能力今天不太行,但我找不到任何东西。 我已运行 ensure index 命令。 我的意图是这些是地图位置。
db.bar.ensureIndex({a:1});
db.bar.ensureIndex({geo:"2d"});
db.<collection>.ensureIndex({point:"2dsphere"});
- AfromanJ3.0.0
版本起,ensureIndex
已被弃用,并且是createIndex
的别名(回答已相应地进行了编辑)。 - Yan Fotofor
{ “near”:{ “type”:“Point”, “coordinates”:[-73.99279,40.719296] }, “distanceField”:“distance” }` - Hassan FaghihidistanceField: 'distance'
之后添加spherical: true
。这对我有用。 - Dakshdb.bar.createIndex({point:"2dsphere"});
? - Sanjayrajsinh