MongoDB $rename

MongoDB $rename

MongoDB 02-03-2023 Saheb Sutradhar

MongoDB $rename

 

How to change the name of document property in mongoDB ?

Using $rename operator we can rename the document in mongoDB , $rename can be used only in updateOne() and updateMany() method 

 

{

test : 'something'

}

If I want to change the name of test property of the above document to description 

db.collection.updateOne({},{$rename:{test:"description"}})

Output:

{

description:"something"

}

Related Posts

Card image cap

MongoDB Basic and CRUD Operations

MongoDB 02-09-2022 Saheb Sutradhar

MongoDB Basic and CRUD Operations ...

Card image cap

MongoDB Read Array Document

MongoDB 05-02-2023 Saheb Sutradhar

MongoDB Read Array Document ...

Card image cap

MongoDB read operation findOne() and find()

MongoDB 05-02-2023 Saheb Sutradhar

MongoDB read operation findOne() and find() ...

Card image cap

MongoDB upsert

MongoDB 02-03-2023 Saheb Sutradhar

MongoDB upsert ...

Card image cap

MongoDB $unset

MongoDB 02-03-2023 Saheb Sutradhar

MongoDB $unset ...

Card image cap

MongoDB array update operation

MongoDB 13-03-2023 Saheb Sutradhar

MongoDB array update operation ...