Javascript mongo findAndUpdateOne在我的案例中失败了
正在尝试进行restful更新 my model.jsJavascript mongo findAndUpdateOne在我的案例中失败了,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,正在尝试进行restful更新 my model.js module.exports.updateGenre = function (id, genre, callback) { var query = {_id: id}; var update = { name: genre.name } Genre.findOneAndUpdate(query, update, option, callback); } 我的路线.js app.put('/a
module.exports.updateGenre = function (id, genre, callback) {
var query = {_id: id};
var update = {
name: genre.name
}
Genre.findOneAndUpdate(query, update, option, callback);
}
我的路线.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)
})
});
我发现
选项不是define
的错误。但我已经在路由中使用null,我怀疑这是一个错误。除了null之外,我还尝试了{}。只需将选项
参数添加到updateGenre
函数:
module.exports.updateGenre = function (id, genre, option, callback) {}
看起来您需要将
选项
参数添加到模块的签名中。目前是:
module.exports.updateGenre = function (id, genre, callback) {
添加选项
,使其看起来像:
module.exports.updateGenre = function (id, genre, option, callback) {
嗯,它没有定义。你的外部签名没有传入的选项,而且它也没有在你自己的函数中定义。啊,多么粗心的一个错误!谢谢