更改 KeystoneJs 列表不会反映在 mongoDB 集合中

Changing the KeystoneJs List does not reflect in mongoDB collection

我用一个简单的例子和​​一个伪代码来解释这种情况。这是我在 KeystoneJs 中的 products 模式:

ProductSchema.add({
    title: { type : String}
})

添加 1000 个产品后,客户要我在产品模型中添加一个 published 字段,所以我更改了代码如下:

ProductSchema.add({
    title: { type : String},
    published: {
    type: Boolean,
    default: true
    }
})

现在,当我想查找所有已发布的产品时,我会这样做:

ProductModel.model.find({published: true});

但是这个查询returns什么都没有,我知道原因是当我在productSchema中添加published字段时,这个变化并没有反映在数据库中,现在如何制作keystone向 MongoDB 集合中的每个文档添加 published 字段?

更改 keystone 模式不会影响数据库,这意味着下次您创建条目时,它将填充默认值。我不确定它是否也会更新从数据库中获取的默认值(我记得在代码中看到过类似的东西,但可能是为了别的东西)。

您必须 运行 自定义查询,无论是独立脚本还是作为整个应用程序的一部分。