Created
September 17, 2013 20:48
-
-
Save stephenmelrose/6600434 to your computer and use it in GitHub Desktop.
Updating multiple elements in a Mongo document array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example document structure | |
{ | |
"balance": { | |
"start": 0, | |
"end": 0 | |
}, | |
"transactions": [ | |
{ "balance": 0 }, | |
{ "balance": 0 }, | |
{ "balance": 0 }, | |
{ "balance": 0 }, | |
{ "balance": 0 } | |
] | |
} | |
// Existing update query | |
db.transaction.update({}, { $inc: { 'balance.start': 5, 'balance.end': 5 } }, { multi: true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment