Skip to content

Instantly share code, notes, and snippets.

@elhoyos
Last active August 29, 2015 14:13
Show Gist options
  • Save elhoyos/2159548a97a49045c4c8 to your computer and use it in GitHub Desktop.
Save elhoyos/2159548a97a49045c4c8 to your computer and use it in GitHub Desktop.
Update a document based on its current values
// Type in a mongoshell
// Credits: http://stackoverflow.com/questions/3788256/mongodb-updating-documents-using-data-from-the-same-document/3792958#3792958
db.currencies.find({symbol: "$"}).snapshot().forEach(
function (e) {
e.customSymbol = e.code.substr(0, 2) + e.customSymbol;
db.currencies.save(e);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment