正在尝试进行一次轻松的更新。
我的 model.js
module.exports.updateGenre = function (id, genre, callback) {
var query = {_id: id};
var update = {
name: genre.name
}
Genre.findOneAndUpdate(query, update, option, callback);
}
我的route.js
app.put('/api/genres/:_id',function(req,res){
var id = req.params._id;
var genre = req.body;
Genres.updateGenre(id, genre, null, function(err,genre){
if(err){
throw err;
}
res.json(genre)
})
});
我收到错误 option is not define
。但我已经在 route 使用了 null,我想知道这是一个错误。除了 null 之外,我还尝试了 {}。
最佳答案
只需将 option
参数添加到您的 updateGenre
函数中即可:
module.exports.updateGenre = function (id, genre, option, callback) {}
关于javascript - mongo findAndUpdateOne 在我的例子中失败了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33840871/