GeoNear 查询出错,无法找到$geoNear查询的索引"



我正在尝试对地理查询进行POC,但我正在获得

 Error: error: {
    "ok" : 0,
    "errmsg" : "error processing query: ns=zircon.storeTree: GEONEAR  field=start maxdist=0.045045 isNearSphere=1nSort: {}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"),
  "location": {
    "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")
}
```
请建议我在这里做错了什么。是什么原因导致地球探测器仍然不工作。

有同样的错误,问题是我在我的"位置"上创建了索引。"坐标"字段,而不是"位置"字段。这在我的流星开发服务器上工作得很好,但是一旦推送到登台服务器,数据库就找不到索引了。

创建2dspere索引时,您应该使用"复合"方法,并按照mongo文档在父位置字段上执行:https://docs.mongodb.com/manual/core/2dsphere/#id1

给定您的json文件和db名称,我会尝试以下操作:db.store。方法createIndex({"位置":"2 dspere"})或db.store。ensureIndex({"位置":"2 dspere"})

您需要为位置值提供索引。

例子:

{ location : { $near : [ -73.9667, 40.78 ], $maxDistance: 0.10 } }

最新更新