Articles → MONGODB → $Rename Operator In Mongodb

$Rename Operator In Mongodb






Purpose





Syntax


db.collection.updateOne(   { [query] },   { $rename: { "[oldField]": "[newField]" } })



Example




Picture showing the sample mongodb collection




db.Employees.updateMany({},{$rename:{"name":"fullname"}})


Picture showing renaming the name field to fullname



Output


Picture showing fields of collection after renamed





Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, March 19, 2024

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250