Created
September 27, 2012 20:28
-
-
Save flavianmissi/3796276 to your computer and use it in GitHub Desktop.
mongodb "migration" script
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
// changes the data in db.collection[from] to | |
// db.collection[to] and deletes db.collection[from] | |
// how can I force the execution of the variables from and to? | |
function changeFieldKey(collection) { | |
var docs = db[collection].find({"from-key": {$exists: true}}); | |
for (var i = 0; i < docs.length(); i++) { | |
print(docs[i]) | |
docs[i]["to-key"] = docs[i]["from-key"]; | |
delete docs[i]["from-key"]; | |
print(docs[i]) | |
db[collection].save(docs[i]); | |
} | |
} | |
changeFieldKey("apps") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment