如何在示例文档中填充“组件”:
{ "__v": 1, "_id": "5252875356f64d6d28000001", "pages": [ { "__v": 1, "_id": "5252875a56f64d6d28000002", "page": { "components": [ "525287a01877a68528000001" ] } } ], "author": "Book Author", "title": "Book Title" }
这是我的JS,可从Mongoose获取文档:
Project.findById(id).populate('pages').exec(function(err, project) { res.json(project); });
猫鼬4.5支持此
Project.find(query) .populate({ path: 'pages', populate: { path: 'components', model: 'Component' } }) .exec(function(err, docs) {});
您可以加入不止一个深层次