【问题标题】:mongodb: can't get query executor when executing geoNear aggregatemongodb:执行geoNear聚合时无法获取查询执行器
【发布时间】:2017-05-06 00:40:33
【问题描述】:

执行以下聚合时

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

我收到以下错误

uncaught exception: aggregate failed: {
    "errmsg" : "exception: geoNear command failed: { ok: 0.0, errmsg: \"can't get query executor\" }",
    "code" : 16604,
    "ok" : 0
}

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

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

任何想法我在做什么?

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    问题可能是:

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

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

    db.Activities.getIndexes()
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,但找到了一个不明显的解决方案。

      这是索引:

      db.buildings.createIndex(
          {    
              'Address.CityCode': 1,
              'Rooms.Categories': 1,
              'Address.Coords': '2dsphere'
          },
          {
              background: true,
              name: 'IX_Address.CityCode_Rooms.Category_Address.Coords_Published',
              partialFilterExpression: { 'Rooms.Published': true }
          }
      );
      

      所以我得到了 “无法获取查询执行程序”,原因有 2 件事:

      • 正如它所看到的那样,索引是复合的,并且正如 here 所告知的那样,您的 查询 必须包含索引中的所有字段
      • 其次,在尝试了索引选项后,发现 'partialFilterExpression' 也会导致同样的错误。

      【讨论】:

        【解决方案3】:

        也许您有一个复合索引、一个 2sphere 和另一种类型的索引,例如:

        {
            "name: 1,
            "location" : "2dsphere"
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-11-11
          • 1970-01-01
          • 2013-04-29
          • 1970-01-01
          • 1970-01-01
          • 2016-12-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多