node.js - Populate nested array in mongoose -
how can populate "components" in example document:
{ "__v": 1, "_id": "5252875356f64d6d28000001", "pages": [ { "__v": 1, "_id": "5252875a56f64d6d28000002", "page": { "components": [ "525287a01877a68528000001" ] } } ], "author": "book author", "title": "book title" }
this js document mongoose:
project.findbyid(id).populate('pages').exec(function(err, project) { res.json(project); });
mongoose 4.5 support this
project.find(query) .populate({ path: 'pages', populate: { path: 'components', model: 'component' } }) .exec(function(err, docs) {});
Comments
Post a Comment