Alex Rivera | Logout

Update a value in MongoDB based on its current value

Asked 2010-03-19T19:23:15.203
27

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?

Edit
Report

1 Answer

5

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

answered 2010-03-19T20:12:56.673

Your Answer