$ geoNear仅在管道的第一阶段有效

时间:2020-05-03 20:46:58

标签: javascript node.js database mongodb geolocation

使用$geoNear is only valid as the first stage in a pipeline.作为服务器端进行聚合时,出现以下错误nodejs

聚合对象:

[ { '$geoNear':
     { near: [Object], distanceField: 'distance', spherical: true } },
  { '$lookup':
     { from: 'reviews',
       localField: '_id',
       foreignField: 'restaurant',
       as: 'reviews' } },
  { '$project':
     { logo: '$$ROOT.logo',
       name: '$$ROOT.name',
       cuisine: '$$ROOT.cuisine',
       rate: [Object],
       reservation: '$$ROOT.reservation',
       closeAt: '$$ROOT.closeAt',
       openAt: '$$ROOT.openAt',
       recommendationsLength: [Object],
       isLive: '$$ROOT.isLive',
       avgCost: '$$ROOT.avgCost',
       creationDate: '$$ROOT.creationDate',
       distance: '$$ROOT.distance' } },
  { '$sort': { distance: 1 } } ]

任何想法我为什么会遇到上述错误?

1 个答案:

答案 0 :(得分:0)

检查并查看是否有任何中间件功能执行聚合。如果是这样,则可能是错误的根源。