Return certain fields with .populate() from Mongoose

前端 未结 10 1709
栀梦
栀梦 2021-01-30 10:11

I\'m getting returned a JSON value from MongoDB after I run my query. The problem is I do not want to return all the JSON associated with my return, I tried searching the docs a

10条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 10:27

    Try to do this:

    applicantListToExport: function (query, callback) {
      this
       .find(query).select({'advtId': 0})
       .populate({
          path: 'influId',
          model: 'influencer',
          select: { '_id': 1,'user':1},
          populate: {
            path: 'userid',
            model: 'User'
          }
       })
     .populate('campaignId',{'campaignTitle':1})
     .exec(callback);
    }
    

提交回复
热议问题