Let's say you don't want the fields houseNum
and street
in the address
field of the final populated doc, use the populate()
as follows,
Person.findOne({_id: req.params.id})
.populate('address', '-houseNum -street') // note the `-` symbol
.exec(function(err, person) {
// do something.
// variable `person` contains the final populated data
});
Or
Person.findOne({_id: req.params.id}, function(err, person) {
// do something
// variable `person` contains the final populated data
})
.populate('address', '-houseNum -street'); // note the `-` symbol
This will produce the following final populated doc,
Populated Doc
{
"_id":"123abc",
"fname":"John",
"mname":"Kennedy",
"lname":"Doe",
"address":{
"_id":"456def",
"city":"City of the dead",
"state":"AB",
"country:"PH"
}
}