我有一个配置文件模式,集合中已经有许多文档,看起来像这样:
const Profile = new Schema({
field_one: String,
field_two: String
}, { timestamps: true })
现在我刚刚添加了一些字段,所以现在架构如下所示:
const Profile = new Schema({
field_one: String,
field_two: String,
new_field_one: { type: String, default: "Value" },
new_field_two: { type: String, default: "Value" },
}, { timestamps: true })
在我的端点中,我看到正在保存的对象的控制台日志,如下所示:
const profile = await Profile.create({ ...body })
console.log(body) prints { field_one: "value", field_two: "value", new_field_one: "something", new_field_two: "something" }
但是 new_field_one 和 new_field_two 没有存储在数据库中。我已经添加了默认值,并向架构添加了 strict false,但没有运气。有没有办法做到这一点,我不必删除现有模型中的所有数据并将其全部重写到另一个模型,然后使用新密钥将其重写到原始模型?