的ID字段我用這樣的代碼創建用戶帳戶:獲取創建的模型
User.create({
email: req.param('email'),
password: req.param('password')
}).exec(function(err, user) {
// I want to get the user ID in here...
});
,我要搶在回調函數中新創建的用戶ID。如果我檢查回調函數的user
參數爲exec()
它沒有ID字段,只有我傳入的字段(email
,password
)和時間戳(createdAt
,updatedAt
)。
我能想到的唯一方法就是在用戶的電子郵件地址創建完成後再次查找用戶,但這是一個非常糟糕的方式。
如何獲取新創建的用戶的ID?