2016-02-04 108 views
0

我的問題是在下面的註釋代碼中的功能。我的文檔何時使用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? 
      }); 
+1

它立即被保存,但'save'方法是異步的,因爲中間件調用本地代碼來執行保存 – adeneo

+0

@chridam oops,在我的真實代碼中,我做了正確的 –

回答

1

只要代碼執行,它就會被保存。在中間件中有一些驗證,但是否則是即時的。

相關問題