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

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

本文介绍了mongodb:执行geoNear聚合时无法获取查询执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下汇总时

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命令时,它运行正常.

when i run the geoNear command, it works fine.

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

任何想法我在做什么?

Any ideas what i am doing worng ?

推荐答案

问题可能是:

  1. 您在集合Activities中缺少"2dsphere"索引.
  2. 集合Activities
  3. 中有多个地理位置索引
  1. You are missing a "2dsphere" index in collection Activities.
  2. There are multiple geo indexes in collection Activities

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

Run this code in Mongo shell to see all the indexes

db.Activities.getIndexes()

这篇关于mongodb:执行geoNear聚合时无法获取查询执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 21:53