我试图用猫鼬在数据库上编辑实例,除非我在函数之后使用then,否则update和updateone函数对我不起作用
此代码有效:
Word.findOne({word:req.body.word}).then(function (res) {
if (res === null) {
const new_word = new Word({
word: req.body.word,translate: req.body.translation
});
new_word.save();
}
else
res.updateone({translate: req.body.translation}).then(function () {});
});
此代码无效:
Word.findOne({word:req.body.word}).then(function (res) {
if (res === null) {
const new_word = new Word({
word: req.body.word,translate: req.body.translation
});
new_word.save();
}
else
res.updateone({translate: req.body.translation});
});
预先感谢您:)