mongodb如何根据简单的条件来更新数据。
发布于 7 年前 作者 maxxfire 3478 次浏览 来自 问答

比如,表中有一个积分字段credit,现在需要在不同的条件下增加不同的积分,如: 当credit < 100 时,credit增加50; 当credit >= 100 && credit < 1000 时,credit增加20; 当credit >= 1000 时,credit增加10;

怎么做更新操作,能否用简洁快速的语句进行更新?

3 回复

@lpbird 是不是要:查询-更新-保存,3步操作。 能不能一步到位?

@maxxfire 一步就可以啊, 类似 x.update({ “_id”:"" },{ “credit”:{"$inc":50 } })

回到顶部