Skip to content

Instantly share code, notes, and snippets.

@stephenmelrose
Created September 17, 2013 20:48
Show Gist options
  • Save stephenmelrose/6600434 to your computer and use it in GitHub Desktop.
Save stephenmelrose/6600434 to your computer and use it in GitHub Desktop.
Updating multiple elements in a Mongo document array
// 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