0 votes
1 view
in SQL by (27.5k points)

Assuming I have a collection in MongoDB with 5000 records, each containing something similar to:


"name": { 




Is there an easy way to rename the field "additional" to "last" in all documents? I saw the $rename operator in the documentation but I'm not really clear on how to specify a subfield.

1 Answer

0 votes
by (67.1k points)

To rename a field for all documents in MongoDB you should try the below-mentioned code:-

 db.collectionName.update({}, { $rename : { 'name.additional' : 'name.last' } }, { multi: true } )