Aggregate.geoNear 中 query 不能为 Command 形式?
发布于 5 年前 作者 xiangqiang 8348 次浏览 来自 官方Issues

Aggregate.geoNear 中 query 不能为 Command 形式?

db.collection('shop').aggregate()
  .geoNear({
    distanceField: 'distance', // 输出的每个记录中 distance 即是与给定点的距离
    spherical: true,
    // limit: 1,
    maxDistance: 5000,
    near: db.Geo.Point(longitude, latitude),
    query: 
      {
        _id: _.exists(false)
      }
    ,
    key: 'geo', // 若只有 location 一个地理位置索引的字段,则不需填
    includeLocs: 'geo', // 若只有 location 一个是地理位置,则不需填
  })
.end()

依然能够返回结果.

回到顶部