Update a value in MongoDB based on its current value
-
21-09-2019 - |
Question
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?
Solution
Yes, you can't refer to other fields in the modifier. You'll have to use db.eval.
OTHER TIPS
Good example can be found here MongoDB: Updating documents using data from the same document
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow