首页 > 解决方案 > $geoNear 仅作为管道中的第一阶段有效

问题描述

在使用服务器端$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 } } ]

知道为什么我会收到上述错误吗?

标签: javascriptnode.jsdatabasemongodbgeolocation

解决方案


检查并查看是否有任何预中间件函数执行聚合。如果是这样,那么这很可能是错误的根源。


推荐阅读