What do you do with the original data after mongodb adjusts the schema?

after mongodb has designed the schema, it has been running normally for some time (data is already available). When you adjust the schema later, for example, to add a field and decrease a field, what to do with the original data? do you have to wash the data first? Or.

Mar.30,2021

after schema has been designed
if you want to add fields, execute the mongo command: db.yourtable.update ({}, {$set: {addField: ""}, false,true)
if you want to delete fields, execute the mongo command: `field ({}, {$unset: {deleteField: ""}, false,true)

Note: if the amount of data in the table is too large, you can consider adding some Filter conditions at query to achieve the effect of batch execution.


the original data is still there, so you can delete it one by one or modify it one by one. If the data is huge, you can directly do error compatibility processing, which is less. The table of the field needs to be handled specially.
the best thing, of course, is to be consistent with schema, so it's best to replace all data

Menu