Mongoose/Mongodb: Exclude fields from populated query data

后端 未结 4 649
灰色年华
灰色年华 2020-12-31 03:31

I use the following mongoose query in a MEAN-environment to find and output a particular author and his corresponding books.

Author
.findOne({personcode: co         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 03:41

    The second parameter of populate is a field selection string, so you can do this as:

    Author
      .findOne({personcode: code})
      .select('-_id -__v')
      .populate('bookids', '-_id -__v')
      .exec(function (err, data) {
        //foo
    });
    

    Note that you should combine your field selections into a single string.

提交回复
热议问题