mercredi 27 juillet 2022

Mongo generate dynamic docs from static docs best practice

I have a software design best practice question.

Lets say i have two types of collections:

  1. Static - template of data with which to genreate the second type, rearly changed.
  2. Dynamic - should have all the data from the first type but with additional data that can be changes frequently.

For example: Lets say Car is a static collection with data such as {name, brand, size, price}. And now when user buy a car I want to create a dynamic documents collection for the UserCar with the same data {name, brand ... } and also new data { condition, accidents, buyingDate ..}. The second data can be changed a lot while the first collection is more like a template for creating the second one.

My question is as follow, should I use a reference key in the second document and not duplicate the data, or should I duplicate the data to the UserCar for each new document?

first approach will require me to do some joins between the two collection each time I want to fetch the cars, while the second approach will require me to save a lot of duplicate data. Which one is better?

Aucun commentaire:

Enregistrer un commentaire