Skip to content

Instantly share code, notes, and snippets.

@paulodelgado
Created February 14, 2011 21:26
Show Gist options
  • Save paulodelgado/826584 to your computer and use it in GitHub Desktop.
Save paulodelgado/826584 to your computer and use it in GitHub Desktop.
mass rename of an attribute in Mongo
// Mass rename of an attribute in Mongo
var cursor = db.my_collection.find({old_attribute: {$exists: true}});
while(cursor.hasNext()) {
db.my_collection.update({_id:elem._id}, {$unset: {old_attribute:1}, $set: {new_attribute: elem.old_attribute}});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment