我正在尝试使用mongoose将记录插入到mongodb中,但是当记录已经存在于数据库中时,记录不会更新.有什么我做错了吗?mongoose的文档对我来说并不是最容易理解的.
models.fg_records.update({email:clean_email}, inactive_user, {update: true}, function (err) {
if(err){
throw err;
console.log(err);
} else {
// send mail with defined transport object
transport.sendMail(message, function(err, response) {
if(err) {
console.log(err);
view('<ul><li>There was a problem sending an email to this user. Make sure you types it correctly.</li></ul>');
} else {
res.redirect('/records');
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
尝试将选项'upsert'传递给更新函数,而不是'update',这不是有效的选项文档.
models.fg_records.update({email:clean_email}, inactive_user, {upsert: true}, function (err) { ... }):
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4487 次 |
| 最近记录: |