mardi 31 mars 2015

Possible to populate two levels?

Say I have collections/documents like below:


question collection:



{
_id: ObjectId("0000"),
title: "test question",
survey: ObjectId("1234") //abbreviated for question assume this is a legit object id
}




survey collection:



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




user collection:



{
_id: ObjectId("5678"),
Name: "Abe"
}


Is there a way for me to call something like:



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


to get the user information along with the question? I understand that I can populate immediate parents of question, but I'm curious if it can be done for grandparents.


Aucun commentaire:

Enregistrer un commentaire