Pregunta

Just read a lecture primarily about MongoDB which states that NOSQL is not appropriate for data which is naturally joined? Can't really understand why this is could someone please explain?

¿Fue útil?

Solución

MongoDB does not support JOINs. The reason is that MongoDB is build for clustering, which means that the data is distributed over multiple independent servers. When the data required for a JOIN is distributed over multiple machines on a network, it gets hard to implement it in a performant way. So the MongoDB developers decided to do without joins so they can prioritize scalability.

For that reason it is usually better to model 1:n relations by embedding the sub-documents in the parent document. This works well to model compositions where the child-documents are inseparable from the parent (one invoice consists of multiple positions) but not so much for aggregations where the child-documents can switch parents or even exist independent from the parent-document (one department has multiple employees). And it doesn't work at all for n:m relations (one usergroup has multiple members, and each member can be in multiple usergroups).

When you have such a situation where embedding isn't reasonably possible, you need to mimic joins on the application layer, which is slow because each query requires multiple network-roundtrips.

There are, however, NoSQL databases which work much better with handling relations between data. One subset of NoSQL are graph databases like Neo4j. These handle complex relations between entities even better than relational databases in many cases.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top