dstrelau
dstrelau

Reputation: 353

Update a value in MongoDB based on its current value

I want to do something like this, but the this keyword doesn't seem to be set inside the update statement.

db.items.update({foo:…}, {$set: {bar: this.foo}}, false, true)

Do I have to use eval to accomplish this?

Upvotes: 27

Views: 25695

Answers (1)

kris
kris

Reputation: 23592

Yes, you can't refer to other fields in the modifier. You'll have to use db.eval.

Upvotes: 5

Related Questions