My application is using mongoDB for data persistence and this application is already deployed on production as well and working fine.
Now, there is a client requirement to change the certain section of a collection which is already been used and having a million records in prod.
Collection name is changeRecord
, earlier it was having an embedded section as per below snapshot :
Now, as per new requirement I need to change the extSystem
single embedded system into embedded array and field name from extCRid
to extId
as per below snapshot :
Here as we can see single embedded system has been changed to embedded array and a field name is also changed. I need to perform this activity, but I'm not a DB expert. I'm using mongoDB in my application for last 1 year but it's from java side using spring-boot and spring-mongo.
Please help me to write a DB script for this, as there is already lots of records are there in prod environment, therefore I can't take risk to fail as well. These changes need to be done from DB side only, not from application side.
I tried writing the below script for field name change but not getting through for changing into array Type. :
db.changerecord.update({"extSystem":{"$exists":true}}, {$rename:{"extSystem.extCRid":"extSystem.extId"}}, false, true);