/** * Switch from separate `firstName` and `lastName` fields to a single * `name` field and update the last_updated field at the same time */ db.students.updateMany( {}, [ // Set name field by concatenating the firstName and lastName fields { $set : { name : { $concat : [ "$firstName", " ", "$lastName" ] } } }, // Then remove the firstName/lastName fields { $unset : { firstName : 1, lastName : 1 } }, // Set last_updated to the current date/time { $set : { last_updated : "$$NOW" } }, ] );