我正在使用猫鼬,并且有如下所示的用户集合,但是我现在想允许用户保存许多文章,一个文章具有标题,副标题和正文,一个用户可以包含许多文章。< / p>
如何重组用户集合以允许添加文章
const userSchema: Schema = new Schema(
{
email: { type: String, required: true, unique: true },
fullName: { type: String, required: true },
password: { type: String, required: true },
},
{
timestamps: true,
}
);
我正在使用以下内容为用户的收藏集设置新数据,我该如何调整它以允许我设置和获取上面详细介绍的新文章?
const confirmed = await userModel
.findOneAndUpdate(
{ email },
{
$set: { password },
}
)
.exec();
答案 0 :(得分:0)
您可以设置选项strict: false
并将新字段添加(保存)到架构中。
const userSchema: Schema = new Schema(
{
email: { type: String, required: true, unique: true },
fullName: { type: String, required: true },
password: { type: String, required: true },
},
{
strict: false,
timestamps: true,
}
);
这里是docs