i am making an web application and using a mongodb for my database. but im new in mongodb and i just want to know if i still needed to normalize my database like what others do in using RDBMS. that before making a table or database it is normalize.
Normalizing your data like you would with a relational database is usually not a good idea in MongoDB.
Normalization in relational databases is only feasible under the premise that JOINs between tables are relatively cheap. The $lookup
aggregation operator provides some limited JOIN functionality, but it doesn't work with sharded collections. So joins often need to be emulated by the application through multiple subsequent database queries, which is very slow (see question MongoDB and JOINs for more information).
For that reason, you should design your database in a way that the most common queries can be satisfied by querying a single collection, even when this means that you will have some redundancy in your database. A good tool to model 1:n relations are often arrays of sub-objects. However, try to avoid objects which grow indefinitely over time, because in that case they will be moved around the file a lot which will impact write performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With