的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?