Reputation: 1518
I'm trying to populate three collection but I think I'm missing something.
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);
}
});
I couldn't populate the _asset. This responds:
{
"__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
}
]
}
Upvotes: 0
Views: 181
Reputation: 19578
This won't work as mongoose doesn't give option for nested population in current version.
You need to iterate through the _rows
array and manually populate the _rows._asset
Upvotes: 1