Articles → MONGODB → $Rename Operator In Mongodb$Rename Operator In MongodbIn this article, we will discuss the $rename operator in MongoDB.Purpose The $rename operator is used to rename the field within the document.Syntax db.collection.updateOne( { [query] }, { $rename: { "[oldField]": "[newField]" } })Example Consider the following collection: -The requirement is to update the field name to fullname. So, the query would be: -db.Employees.updateMany({},{$rename:{"name":"fullname"}})Output Posted By - Karan Gupta Posted On - Tuesday, March 19, 2024 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
db.collection.updateOne( { [query] }, { $rename: { "[oldField]": "[newField]" } })
db.Employees.updateMany({},{$rename:{"name":"fullname"}})
Query/Feedback