Skip to content

Instantly share code, notes, and snippets.

@jketcham
Last active November 22, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jketcham/f57c94a3aa68d40fa7236d18f332ba65 to your computer and use it in GitHub Desktop.
Save jketcham/f57c94a3aa68d40fa7236d18f332ba65 to your computer and use it in GitHub Desktop.
Updating EmbeddedDocument in an array in MongoDB
db.collection.find({}).snapshot().forEach(function(item) {
for (i = 0; i < item.array.length; i++) {
item.array[i].newProp = item.array[i].oldProp;
delete item.array[i].oldProp;
}
db.collection.update({
_id: item._id
}, item);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment