猫鼬模式
我有一个猫鼬模式
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()
才能将其添加到数据库中。