Last Updated: February 25, 2016
·
1.144K
· fsamir

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" }} );
});