提问者:小点点

“带有”pipeline“的$lookup不能指定”local field“或”foreign field“”


我是mongoose&mongoDB的新手,我有following查询,当运行时会抛出follower错误。如果有人能帮我处理这个问题,并且仍然得到相同的输出,那就太好了

//interview.model.js => mongodb show name as interview
module.exports = mongoose.model('Interview', interviewSchema);
//candidate.model.js => mongodb show name as candidate
module.exports = mongoose.model('Candidate', candidateSchema);

const [result, err] = await of(Interview.aggregate([
         {
           $match: {
             ...filterQuery,
           }
         },
         {
           $lookup: {
             'from': 'candidates',
             'localField': 'candidateId',
             'foreignField': '_id',
             'as': 'candidateId',
             pipeline: [
               { $match: { 'candidateId.interviewCount': 0 }},
               { $project: { firstName:1, status:1, avatar:1 } }
             ]
           }
         },
       ]))

共1个答案

匿名用户

0

如果管道位于$lookup内部,则不能使用localField或foreignfield。有关语法和示例,请参阅MongoDB文档...