1
嘿,我是mongo和貓鼬的新手。我試圖通過_id upating特定的文檔,但我不斷收到錯誤爲什麼Mongoose模型拋出「TypeError:Object {_id:x}沒有方法'y'」?
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);
});
任何援助將不勝感激