user7742676
user7742676

Reputation:

How is redundant data avoided in non relational databases?

I want to move to mongoose, but I need to understand how my mysql tables will map over to no-sql based databases.

In particular I use joins to avoid replicating data. That is if I have 2 tables ( B & C ) that related 1 table ( A ). I can just join table A to B when needed or join table A to C when needed.

How would this work in mongoose/mongodb i.e. noSQL.

Upvotes: 14

Views: 3660

Answers (1)

Alan
Alan

Reputation: 1428

What you described is normalized data. Normalization in databases is a characteristic of relational databases. Document-oriented NoSQL databases such as MongoDB use a different paradigm where you structure the data around a document paradigm. In this world, the data is arranged into documents (JSON structures). You can point to other structures, but there is always a tradeoff. You have to decide what level of data redundancy works, but that is really a secondary issue. Your first priority in a MongoDB-like world is to figure out what makes the most sense in the context. For instance, you might have a document representing an Invoice with embedded line items, but also a pointer to a separate customer object. You might also, in the same database, have a document designed around the customer that has invoice headers nested, or even invoice lines nested, or invoice headers nested with invoice lines nested inside, or products bought, with or without product catalog information.

Joins are generally expensive in a MongoDB world, but richness of data stored in multiple ways for a range of purposes is a feature well worth using - in the right context.

You should not see MongoDB as a replacement for a relational DBMS, but rather as part of a bigger polyglot (multilanguage) persistence design. You might also use other data tools like Redis and Neo4J as part of that world to do different things.

Horses for courses; MongoDB isn't for everything.

Upvotes: 14

Related Questions