MongoDB $lookup vs Mongoose populate

Thanks to a github thread shared by GrĂ©gory NEUT in the question’s comments I have been able to establish certain facts: Mongoose’s populate() method does not use MongoDB’s $lookup behind the scenes. It simply makes another query to the database. Mongoose does not have functionalities that MongoDB does not have. populate() just makes two or … Read more

Multiple schema references in single schema array – mongoose

What you are looking for here is the mongoose .discriminator() method. This basically allows you to store objects of different types in the same collection, but have them as distinquishable first class objects. Note that the “same collection” principle here is important to how .populate() works and the definition of the reference in the containing … Read more

Mongoose populate nested array

Update: Please see Trinh Hoang Nhu’s answer for a more compact version that was added in Mongoose 4. Summarized below: Car .find() .populate({ path: ‘partIds’, model: ‘Part’, populate: { path: ‘otherIds’, model: ‘Other’ } }) Mongoose 3 and below: Car .find() .populate(‘partIds’) .exec(function(err, docs) { if(err) return callback(err); Car.populate(docs, { path: ‘partIds.otherIds’, model: ‘Other’ }, … Read more