如何在MongoDB的一个命令中更新两个字段的增量? [英] How can I update increment two fields in one command in MongoDB?
本文介绍了如何在MongoDB的一个命令中更新两个字段的增量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文档告诉我,如果我想设置一个值并增加另一个值,这是合法的:
The documentation tells me this is legal if I want to set one value and increment another:
{ $set : { x : 1 }, $inc : { y : 1 } }
如果我想增加两个变量该怎么办?我正在尝试此方法,但是它不起作用:
What if I want increment both variables? I'm trying this but it isn't working:
{ $inc : [{ y : 1 }, { x : 1 }] }
这可能吗?
推荐答案
我是个白痴:
{ $inc : { y : 1, x : 1 } }
这篇关于如何在MongoDB的一个命令中更新两个字段的增量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文