Find Child's of Child document in Mongoose Node JS
This Article is basically to populate records/data/documents of child table and also for populate records/data/documents from Child's of child table in mongoose(Mongo DB).
Suppose, you have three tables
1) Subjects
2) Chapters
3) Questions
Questions schema is having the reference of Chapters (_id) and Chapters is having reference of Subjects (_id). So this is the Many to One relationship between them.
Suppose, you have three tables
1) Subjects
2) Chapters
3) Questions
Questions schema is having the reference of Chapters (_id) and Chapters is having reference of Subjects (_id). So this is the Many to One relationship between them.
If developer wants to populate Chapter name and Subject name with the Questions. Then you have to write find query like below:
Questions.find({})
.populate({
path: 'Chapters',
populate: {
path: 'Subjects',
model: 'Subjects'
}
})
Thanks for reading this article. Please share your comments on this article.
Today I was riding in a bus and heard how the boys talked about this site secure online casino sites Speak as if it’s cool for a couple of hours so much money decided to take a risk and really thank you guys
ReplyDelete