I think we can improve the depth of the populate function including support for nested arrays. Suppose the next scenario
A simple model referring to other collection multiple times on an array of IDs
var postSchema = new mongoose.Schema({
comments: [{ type: mongoose.Schema.Types.ObjectId, ref: "comments" }]
});
var Post = mongoose.model("post", postSchema);
A second model with the same structure referring to the same or another collection
var commentSchema = new mongoose.Schema({
replies: [{ type: mongoose.Schema.Types.ObjectId, ref: "replies" }]
});
var Comment = mongoose.model("comments", commentSchema);
A third model containing the deepest level of information
var replySchema = mongoose.Schema({
// Information for the previous models
});
var Reply = mongoose.model("replies", replySchema);
Hope you can add support for this feature
EDIT: I'm terribly sorry. The solution was in fact very easy. We have to explicit provide the right path to the deepest level i.e.
Post.find().deepPopulate(comments, comments.replies).exec(function (err, posts) {
// Here the post object is fully populated
})
Hi,
I think we can improve the depth of the populate function including support for nested arrays. Suppose the next scenario
A simple model referring to other collection multiple times on an array of IDs
A second model with the same structure referring to the same or another collection
A third model containing the deepest level of information
Hope you can add support for this feature
EDIT: I'm terribly sorry. The solution was in fact very easy. We have to explicit provide the right path to the deepest level i.e.