Having enabled mongoose schema virtuals as such ...
User.set('toJSON', { virtuals: true });
and created several virtuals...
User.virtual('todoCount').get(function(){
return this.todos.length;
});
User.virtual('friendCount').get(function(){
return this.friends.length;
});
I can now see my virtuals in the response. When I query Users...
User.findById(req.body.id, function (err, user) { // and soforth
However, I get back ALL virtuals every time. How can I request/remove only certain virtuals. Doing either of the following doesn't seem to remove the virtual property from my output?
User.findById(req.body.id, '-friendCount').exec(function (err, user) { ...blah blah...
OR
delete user.friendCount; //before res.json returns user
I ask because I'd like to be able to turn certain virtual properties on and off based on URL parameters and really can't work out where to go from here.
All help greatly appreciated!