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
// Params | |
// 1. {} add a query in here if you don't want to select all records (unlikely) | |
// 2. $rename one or more fields by setting the keys of the object to the old field name and their values to the new field name. | |
// 3. Set multi to true to force it to operate on all documents otherwise it will only operate on the first document that matches the query. | |
// | |
// Run this in the MongoDB shell. | |
db.<collectionName>.update( {}, { $rename: { '<oldName1>': '<newName1>', '<oldName2>': '<newName2>' } }, {multi: true} ) |