In this tutorial will see how to modify/rename  json keys without deleting/Modifying the Json Object for respective key.

I have an document shown below

Now I want to update the key “key1” to “key” in “json1” object  without delete or re adding the document.

with the help of dotted notation we are telling Mongo DB to update particular node with specific key should be updated or modify with name we want. below is the Query

from above Query we are mentioning object in “json1” with key “key1” need to be rename with “key” by using dot notation.

in the Query we have mentioned multi:true we are telling mongo db to update multiple records which are matching with the same pattern “json1.key1” from all documents

 

After executing the Query below is the output.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *