我正在尝试对geonear查询进行POC,但我得到了
Error: error: {
"ok" : 0,
"errmsg" : "error processing query: ns=zircon.storeTree: GEONEAR field=start maxdist=0.045045 isNearSphere=1\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query",
"code" : 2我也创建了我的基本索引。
> db.store.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "zircon.store"
},
{
"v" : 1,
"key" : {
"point" : "2dsphere"
},
"name" : "point_2dsphere",
"ns" : "zircon.store",
"2dsphereIndexVersion" : 3
},
{
"v" : 1,
"key" : {
"location.Point" : "2dsphere"
},
"name" : "location.Point_2dsphere",
"ns" : "zircon.store",
"2dsphereIndexVersion" : 3
}
] 我的模型是
```json{
"_id":ObjectId("57b4d4437ab5db070e8cc02d"),
“位置”:{
"Point": { "x": 47.629104999999996, "y": 77.21983919}},
"name":"Gulati XX :19",
"createdDate":ISODate("2016-08-17T21:16:51.605Z"),
"modifiedDate":ISODate("2016-08-17T21:16:51.605Z")
}
请建议我在这里做错了什么..是什么原因导致geonear仍然无法工作。
发布于 2017-05-02 23:45:30
也有同样的错误,问题是我在"location.coordinates“字段而不是"location”字段上创建了索引。这在我的meteor开发服务器上运行得很好,但是一旦推送到临时服务器,db就无法找到索引。
在创建2dspee索引时,您应该使用“复合”方法,并按照mongo docs:https://docs.mongodb.com/manual/core/2dsphere/#id1在parrent location字段上执行此操作。
给定您的json文件和数据库名称,我将尝试执行以下操作: db.store.createIndex({"location":“2dspee”})或db.store.ensureIndex({"location":“2dspee”})
发布于 2016-08-19 17:20:34
您需要为位置值提供索引。
示例:
{ location : { $near : [ -73.9667, 40.78 ], $maxDistance: 0.10 } }https://stackoverflow.com/questions/39006635
复制相似问题