Datafix or Codefix for existing records?

24 views
Skip to first unread message

vishc...@gmail.com

unread,
May 25, 2017, 8:00:02 PM5/25/17
to mongodb-user
We have a NodeJS/Java application deployed in Live Env for the last 4 months. It uses MongoDB as the backend. 
The Application creates new customer records with 20 fields and so far it has created 1000 customers in the MongoDB database in Live Env.
We have a new requirement which requires a new field called "Rating" to be added to the Customer Collection.
The new version of the Application is expected to create new customer records with this new field now with different values.

I think I have 2 approaches : 

1. Would it be better to go for a  "datafix" script to modify the existing 1000 records to have the new "Rating" field populated with the default value 5
    in Production env during the deployment of the new version of the application?

or 

2. Would it be better to go for a "codefix" approach, where no changes are performed to the existing customer records in the MongoDB database.
    If there is no field called "Rating" for an existing Customer record, the Application will always consider it as having a "Rating" field with a default value of 5.
    MongoDB is a schemaless NoSQL database, so I think this approach can be used.


Coming from a relational database background, I like approach 1. I would like to keep the database clean and consistent with the number of fields the same and correctly populated for all records of a collection.

I am fairly new to MongoDB database, 

I was wondering what other MongoDB experienced users think about these 2 approaches..


Kevin Adistambha

unread,
May 31, 2017, 11:57:39 PM5/31/17
to mongodb-user

Hi

Coming from a relational database background, I like approach 1. I would like to keep the database clean and consistent with the number of fields the same and correctly populated for all records of a collection.

The answer to your question very much depends on how you would like to proceed, e.g. which approach feels more maintainable for you and your team in the future, and which solution aligns better with your application’s use case. For example, following approach #1, would you feel comfortable to perform another datafix should you add more features to your application in the future? In contrast, if you follow approach #2, would you feel adding default values in the code more (or less) maintainable? You could theoretically have a mix of both approaches as well. For example, doing datafix for what you consider to be essential fields that must stay consistent across the whole collection, and doing codefix for things not deemed to be essential. Note that MongoDB supports either approach without any issue.

You may want to browse the following links for more information:

Best regards,
Kevin

vishc...@gmail.com

unread,
Jun 2, 2017, 8:05:19 AM6/2/17
to mongodb-user

thanks Kevin,
 
      I will go through the useful links.
Reply all
Reply to author
Forward
0 new messages