javascript - Mongoose doesn't seem to support the $max field update operator, any advice? -
i'm trying make use of the $max update operator in node.js project using mongoose, think a) i'm either doing horribly wrong or b) mongoose doesn't support functionality. (using example):
var updategamescores = function(game, newscore, callback) {   models.scores.update({     gamename: game   }, {     $set: {       $max: {         highestscore: newscore       }     }   }, {     upsert: true   }, function(err) {     callback(err);   }); }; gives me following error:
mongoerror: dollar ($) prefixed field '$max' in '$max' not valid storage. i couldn't find (or similar functionality) in mongoose docs, suggests mongoose doesn't support this. if indeed case, there alternative ways can achieve this** while minimizing number of database operations?
**: "update value of field specified value if specified value greater current value of field"
thanks in advance.
consider writing update expression
{ $max: { highestscore: newscore } } since $max operator implies $set.
Comments
Post a Comment