我试图填充三个收藏品,但我想我错过了一些东西。
var BlogsSchema = new Schema({
name: String,
url: {type:String, unique: true},
_rows: [{type: Schema.Types.ObjectId, ref:'Rows'}],
description: String,
tags:[{type:String}]
});
var RowsSchema = new Schema({
name: String,
text: String,
_asset: {
type: Schema.Types.ObjectId,
ref: 'Assets'
}
});
Blogs.find()
.populate('_rows')
.populate('_rows._asset')
.exec(function (err, blogs) {
if (!err) {
var _id = [];
return res.json(blogs);
} else {
return res.send(err);
}
});
我无法填充_asset。这回应:
{
"__v": 0,
"_id": "532acfa26f192fdc1e000002",
"description": "deneme deneme",
"name": "Deneme",
"url": "deneme",
"tags": [
"deneme1",
"deneme2"
],
"_rows": [
{
"name": "asdfadf",
"text": "asdfadsf",
"_id": "532acfa96f192fdc1e000003",
"__v": 0
},
{
"name": "asdfsfdb",
"text": "bodfbsdfbsdbsdb",
"_asset": "5327ca7006777b6c0e000003", // this should populated too. Not _id
"_id": "532acfe36f192fdc1e000004",
"__v": 0
}
]
}
答案 0 :(得分:1)
这不起作用,因为mongoose不为当前版本的嵌套填充提供选项。
您需要遍历_rows
数组并手动填充_rows._asset