【问题标题】:Mongoose populate in Windows not working like in LinuxMongoose 在 Windows 中的填充不像在 Linux 中那样工作
【发布时间】:2017-01-14 03:20:13
【问题描述】:

我有这个架构(简化)

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
});

当我打电话时

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
    });
});

结果只包含没有图像的文本。

但是,如果我填充它

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

我只得到没有文字的图像。

这个问题好像只出现在windows上 我用: MongoDB 外壳版本:3.2.10 猫鼬:^4.6.4

【问题讨论】:

    标签: node.js mongodb mongoose mongoose-populate


    【解决方案1】:

    在模型中你过去的字符串你应该传递 var 模型

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

    【讨论】:

      猜你喜欢
      • 2015-02-07
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      • 2020-01-30
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多