node.js - Possible to populate two levels? -


say have collections/documents below:

question collection:

{    _id: objectid("0000"),    title: "test question",    survey: objectid("1234") //abbreviated question assume legit object id } 

survey collection:

{    _id: objectid("1234"),    title: "survey title!",    user: objectid("5678") } 

user collection:

{    _id: objectid("5678"),    name: "abe" } 

is there way me call like:

questions.findone({_id: "0000"}).populate("survey.user") 

to user information along question? understand can populate immediate parents of question, i'm curious if can done grandparents.

you need in 2 steps; first populating survey, , populating survey.user using separate call model.populate:

questions.findone({_id: '0000'})     .populate('survey')     .exec(function(err, question) {         questions.populate(             question,             { path: 'survey.user', model: 'user'},             function(err, question) {...});     }); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -