尝试使用 findByIdAndUpdate 更新 MongoDB 文档:
var landmarkModel = mongoose.model('landmark', landmarkSchema, 'landmarks');
var lm = new landmarkModel();
//adding data to schema here, like: lm.name = req.body.name;
lm.findByIdAndUpdate(req.body._id, lm, function (err, landmark) {
if (err)
console.log(err);
else{
console.log(null, landmark);
}
});
返回错误:Object lm has no method 'findByIdAndUpdate'
我试过用它换掉这个lm.findByIdAndUpdate
值,landmarkModel.findByIdAndUpdate
但这也不起作用。我究竟做错了什么?