嘿,我是 mongo 和 mongoose 的新手。我尝试通过 _id 更新特定文档,但我不断收到错误
TypeError: Object { _id: 4fd02c1d50071a5713000001 } has no method 'update'.
我的代码如下:
//Update comment or increment vote up or vote down
app.put('/comments/voteUp/:commentid', function(request, response){
var id = mongoose.Types.ObjectId(request.params.commentid);
var conditions = { "_id": request.params.commentid }
, update = {$inc: { 'meta.voteUp': 1 } }
, options = { multi: false };
console.log(conditions);
var comment = new CommentModel();
comment.update( { "_id": id, update, options, callback );
function callback (err, numAffected) {
response.send("numAffected: " + numAffected);
}
console.log("commentid: " + request.params.commentid);
});
任何帮助将不胜感激