mongodb:执行geoNear聚合时无法获取查询执行程序

Avi*_*hya 5 mongodb

执行以下聚合时

db.Activities.aggregate([
   {
     $geoNear: {
        near: { coordinates: [ -73.99279 , 40.719296 ] },
        distanceField: "location.calculated",
        spherical: true,
     }
   }
])
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

uncaught exception: aggregate failed: {
    "errmsg" : "exception: geoNear command failed: { ok: 0.0, errmsg: \"can't get query executor\" }",
    "code" : 16604,
    "ok" : 0
}
Run Code Online (Sandbox Code Playgroud)

当我运行geoNear命令时,它工作正常.

db.runCommand( {
   geoNear: "Activities" ,
   near: [ -73.99279 , 40.719296 ],
   spherical: true,
})
Run Code Online (Sandbox Code Playgroud)

我在做什么想法?

小智 3

问题可能是:

  1. 您在 collection 中缺少“2dsphere”索引Activities。
  2. 集合中有多个地理索引Activities

在 Mongo shell 中运行此代码以查看所有索引

db.Activities.getIndexes()
Run Code Online (Sandbox Code Playgroud)