Mongoose populate in Windows not working like in Linux

169 Views Asked by At

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

1

There are 1 best solutions below

0
On

in model you past the string you should pass the var model

.populate([
    {
        path: 'items',
        model: text
    }, {
        path: 'items',
        model: image
    }
])