0

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 :

enter image description here

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 :

enter image description here

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);
Community
  • 1
  • 1
Punit
  • 324
  • 1
  • 4
  • 17
  • Any suggestions, please..!! – Punit Sep 19 '17 at 10:50
  • @NeilLunn - I didn't find my query resolution in the link you shared. There is no reference in that link that how we can change it from single embedded system to embedded array. – Punit Sep 20 '17 at 07:38
  • Interesting. Because there's a pretty prominent example using `.aggregate()` and `$out`. And all you really need do it wrap your current value in an array. Perhaps reading the many answers there and linked documentation from them might find a better resolution for you. – Neil Lunn Sep 20 '17 at 07:40

0 Answers0