比如,表中有一个积分字段credit,现在需要在不同的条件下增加不同的积分,如: 当credit < 100 时,credit增加50; 当credit >= 100 && credit < 1000 时,credit增加20; 当credit >= 1000 时,credit增加10;
怎么做更新操作,能否用简洁快速的语句进行更新?
比如,表中有一个积分字段credit,现在需要在不同的条件下增加不同的积分,如: 当credit < 100 时,credit增加50; 当credit >= 100 && credit < 1000 时,credit增加20; 当credit >= 1000 时,credit增加10;
怎么做更新操作,能否用简洁快速的语句进行更新?
@maxxfire 一步就可以啊, 类似 x.update({ "_id":"" },{ "credit":{"$inc":50 } })
$inc