Zach
Zach

Reputation: 19092

How can I update increment two fields in one command in 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 }] }

Is this possible?

Upvotes: 7

Views: 6697

Answers (1)

Zach
Zach

Reputation: 19092

I'm an idiot:

{ $inc : { y : 1, x : 1 } }

Upvotes: 40

Related Questions