Mongoose: deep population (populate a populated field)

前端 未结 10 576
独厮守ぢ
独厮守ぢ 2020-12-02 08:05

I have Category model:

Category:
    ...
    articles: [{type:ObjectId, ref:\'Article\'}]

Article model contains ref to

10条回答
  •  独厮守ぢ
    2020-12-02 08:53

    This concept is deep Population. Here Calendar,Subscription,User,Apartment are mongoose ODM models in different levels

    Calendar.find({}).populate({
          path: 'subscription_id',model: 'Subscription',
             populate: {path: 'user_id',model: 'User',
               populate: {path: 'apartment_id',model: 'Apartment',
                  populate: {path: 'caterer_nonveg_id',
                              model: 'Caterer'}}}}).exec(function(err,data){ 
                              if(!err){
                                 console.log('data all',data)
                               }
                               else{
                                 console.log('err err err',err)
                                }
                       });
    

提交回复
热议问题