Denormalizing or Normalizing. Reactive update, Cascaded update/delete

Mongodb encourages denormalizing your database. But when you have tons of documents in your collection and each has many objects, in terms of scaleability and performance how it is advantageous over normalizing? Developers still use normalizing with mongodb in meteor. However, I cannot find good examples or best practices how to achieve cascaded delete, update and reactive update in existing joined documents. Say for example I join Posts collection with Meteor.users collection with userId() as author. I could do transform function on the Posts collection to get user data of the author, like username and display username of the author on any post. The problem is when user changes his/her username, existing posts won’t update author’s username reactively. I used popular smart packages like publish-composite and collection-helpers. But problem still exists. Any expert meteor dev can help me on this? Thank you.

If you want to denormalize and then cascade changes on the foreign data to all those denormalized fields, you can use matb33:collection-hooks to automate what happens before/after some document gets inserted/updated/removed.

So you can do things like if the username field on the users collection gets an update, go and update the username fields on the posts and comments collections.

You can also automate and abstract that composition using a dedicated denormalization package such as jeanfredrik:denormalize or you can take a more radical approach and use peerlibrary:peerdb as your database layer which replicates relational database features onto mongodb through some external process and additional API’s.

Yes. I was just looking at those packages. I am pretty new to meteor it was really helpful thank you.

1 Like

You might want to search the debates we had about this on this forum.