0

Currently, my Mongo db schema has a model called namecards. And inside the namescards, there are documents called profile(object), links(array of objects), and so on...

namecards: {
    profile:{
        address:{...},
        phoneNumber:{...},
        ...
    },
 
    links:[{...}]
}

By the way, I want to push only a few documents of the namecards profile and links in the array of objects called blocks.

Update Expected Schema

namecards:{
    blocks:[
        {
        address:{...},
        links:[],
        and new added columns , ...        
    },
    {...}
    ]
}

The question here is,

1. Should I delete the profile and link documents of the namecards as soon as I don't need them?
2. If you don't delete it, how is the best way to define a schema?

i tried just add and added... but it didn't wise solution....

yl K
  • 41
  • 3

1 Answers1

0

Actually changing a schema is bit difficult and if you want to change it in production we use the following steps :

  1. We Iterate over the documents of the table .

  2. For each element we just change the data at it's format

  3. Then we update it inside json file . Refer to this to learn about how to store data in a json file.

This is how you have stored important data inside backup.json file After this we can safely change the schema and run a simple query forEach element in json file to insert the data .

This are the best practices we do in production level so that our data is not lost for newer updates or for newer features