Last active
November 22, 2016 18:21
-
-
Save jketcham/f57c94a3aa68d40fa7236d18f332ba65 to your computer and use it in GitHub Desktop.
Updating EmbeddedDocument in an array in MongoDB
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
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