I have this schema (simplified)
post = new schema({
title: String,
items: [schema.Types.ObjectId]
});
image = new schema({
title: String,
header: String,
path: String
});
text = new schema({
title: String,
content: String
});
When I call
postModel.findOne({
_id: ObjectId(req.body.page.id)
}).populate([
{
path: 'items',
model: 'image'
}, {
path: 'items',
model: 'text'
}
]).exec(function(err, article) {
return res.render('main/article', {
title: article.title,
items: article.items
});
});
the result contains only text without images.
However, if I populate it with
.populate([
{
path: 'items',
model: 'text'
}, {
path: 'items',
model: 'image'
}
])
the I get only images without text.
It seems this problem occurs only on windows I use: MongoDB shell version: 3.2.10 mongoose: ^4.6.4
in model you past the string you should pass the var model