Mongoose populate sub-sub document

后端 未结 9 2134
深忆病人
深忆病人 2021-01-30 03:00

I have this setup in my MongoDB

Items:

title: String
comments: [] // of objectId\'s

Comments:

user: ObjectId()
item: Ob         


        
9条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 03:20

    Simpler

    Item
      .find({})
      .populate({
        path: 'comments.user',
        model: 'users' }
      })
      .exec(function(err, data){
        if (err) return handleError(err);
        res.json(data);
    });
    

提交回复
热议问题