最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

猫鼬模式

IT培训 admin 63浏览 0评论

猫鼬模式

我有一个猫鼬模式

const test = new Schema({
    foo: {}
});

呼叫new test({foo: "bar"})

[有没有一种方法可以像foo一样更改.pre('save')的值,但是在调用new test()时正确吗?

回答如下:如果执行const test = new Test({foo:"bar"});

然后没有任何内容保存到数据库,您仍然可以对其进行修改。像这样:

test.foo = "newBar"

您必须执行test.save()才能将其添加到数据库中。

猫鼬模式

我有一个猫鼬模式

const test = new Schema({
    foo: {}
});

呼叫new test({foo: "bar"})

[有没有一种方法可以像foo一样更改.pre('save')的值,但是在调用new test()时正确吗?

回答如下:如果执行const test = new Test({foo:"bar"});

然后没有任何内容保存到数据库,您仍然可以对其进行修改。像这样:

test.foo = "newBar"

您必须执行test.save()才能将其添加到数据库中。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论