计划器返回错误:找不到$ geoNear查询Python的索引

时间:2018-11-30 19:34:08

标签: python mongodb pymongo geo

我正在尝试使用pymongo在python中使用$ near进行查询,

我已经创建了索引

  

db.operadores.createIndex({location:“ 2dsphere”});

如果我对其进行查询,则:

db.operadores.find(    {
     id: {
     $in:['10335282', '10335539', '10335541', '10476793', '10484737', '10526744', '10552801', '10556323', '10625572', '10759263', '10819053', '10835837', '10842699', '10876588', '10886964', '10892128', '30377476', '70000240', '70000461', '900705728']
     },
     location:
       { $near :    
          {
            $geometry: { type: "Point",  coordinates: [-74.05937569999998, 4.6813047 ] },
            $maxDistance: 5000
          }
       }    }
    ).sort({location:1})

但是在python中,如果我进行查询:

data = self.__operators.find({
            'id': {
                '$in': ['10335282', '10335539', '10335541', '10476793', '10484737', '10526744', '10552801', '10556323', '10625572', '10759263', '10819053', '10835837', '10842699', '10876588', '10886964', '10892128', '30377476', '70000240', '70000461', '900705728']
            },
            'location':
                SON([("$near", [-74.05937569999998, 4.6813047 ]), ("$maxDistance", 1000)])

        })

这告诉我一个例外:

  

 raise OperationFailure(msg % errmsg, code, response)
 pymongo.errors.OperationFailure: error processing query:
 ns=unilever.operadoresTree: $and
     id $in [ "10335282" "10335539" "10335541" "10476793" "10484737" "10526744" "10552801" "10556323" "10625572" "10759263" "10819053"
 "10835837" "10842699" "10876588" "10886964" "10892128" "30377476"
 "70000240" "70000461" "900705728" ]
     GEONEAR  field=location maxdist=1000 isNearSphere=0 Sort: {} Proj: {}  planner returned error: unable to find index for $geoNear query

0 个答案:

没有答案