Mongoose/Mongodb: Exclude fields from populated query data

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.

Leave a Comment