Hey I am new to mongo and mongoose. I tried upating a specific document by _id but I keep on getting an error
TypeError: Object { _id: 4fd02c1d50071a5713000001 } has no method 'update'.
My code is as follows:
//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);
});
Any assistance will be greatly appreciated
update
is a method of your model's constructor function, not of a model instance. So call this instead:
CommentModel.update({"_id": id}, update, options, callback);