Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it needed to normalize your database when you are using mongodb?

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.

like image 263
nsantiago2719 Avatar asked Jul 19 '14 10:07

nsantiago2719


1 Answers

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.

like image 146
Philipp Avatar answered Sep 21 '22 17:09

Philipp