我的文档何时使用Mongoose保存功能保存?
问题描述:
我的问题是在下面的注释代码中的功能。我的文档何时使用Mongoose保存功能保存?
newUser = new User();
newUser.save(function(err){
if(err) console.log('error saving user');
// is my user saved at this point? Can I modify
// the user in here or is this pre-save?
});
答
只要代码执行,它就会被保存。在中间件中有一些验证,但是否则是即时的。
它立即被保存,但'save'方法是异步的,因为中间件调用本地代码来执行保存 – adeneo
@chridam oops,在我的真实代码中,我做了正确的 –