Tutorial by Examples

Mongoose populate is used to show data for referenced documents from other collections. Lets say we have a Person model that has referenced documents called Address. Person Model var Person = mongoose.model('Person', { fname: String, mname: String, lname: String, address: {typ...
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 somet...
If you only want the fields houseNum and street in the address field in the final populated doc, use the populate() function as follows in the above two methods, Person.findOne({_id: req.params.id}) .populate('address', 'houseNum street') .exec(function(err, person) { // do somet...
Lets say you have a user schema, which contains name , contactNo, address, and friends. var UserSchema = new mongoose.Schema({ name : String, contactNo : Number, address : String, friends :[{ type: mongoose.Schema.Types.ObjectId, ref : User }] }); If y...

Page 1 of 1