I have this setup in my MongoDB
Items:
title: String
comments: [] // of objectId\'s
Comments:
user: ObjectId()
item: Ob
Check the screenshot below. This thing works like charm!!!
To add one final method that people may want to use to select only particular fields from sub-documents, you can use the following 'select' syntax:
Model.findOne({ _id: 'example' })
.populate({
path: "comments", // 1st level subdoc (get comments)
populate: { // 2nd level subdoc (get users in comments)
path: "user",
select: 'avatar name _id'// space separated (selected fields only)
}
})
.exec((err, res) => {
// etc
});
This worked for me:
i.e. no need for model
.populate({
path: 'filters',
populate: {
path: 'tags',
populate: {
path: 'votes.user'
}
}
})
.populate({
path: 'members'
})