MongoDB: rename a field in all collections
With this simples script you can rename all fields in all collection. It can be used to update field values, as well.
var collections = db.getCollectionNames()
collections.forEach(function(collectionName) {
var collection = db.getCollection(collectionName)
collection.update ( {}, { $rename : { "oldFieldName" : "newFieldName" }} );
});
Written by Franklin Dattein
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mongodb
Authors
Related Tags
#mongodb
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#