mongo之$max

原集合:

{ _id: 1, highScore: 800, lowScore: 200 }

应用:

#意思是:更新_id 等于1 的记录,条件是highScore 950>原纪录的highScore 800,才更新
db.scores.update( { _id: 1 }, { $max: { highScore: 950 } } )
#结果:
{ _id: 1, highScore: 950, lowScore: 200 }

注:

#如果换成 则操作无效,因为该字段的当前值`highScore`,即800大于700:
db.scores.update( { _id: 1 }, { $max: { highScore: 700 } } )
原文地址:https://www.cnblogs.com/zzy-9318/p/10003435.html