MongoDB: What is Normalized Data?

Alright! We’re on week 9 (out of 12) of our Orange County Code School bootcamp – four more weeks left! I’ve just wrapped up my 2nd project and will be doing a recap post about it soon. We’ve been learning about MongoDB and MongooseJS in class. Mongoose is an object modeling package for Node, and allows access to the MongoDB commands for CRUD (Create, Read, Update, Destroy).

I was doing some exercises, and came across two terms that I had no idea about: Normalized Data, and Embedded Data. Yeah, I know… what?

Here’s a quick recap from me reading of https://docs.mongodb.org/manual/core/data-model-design/

Normalized data models describe relationships using references between documents.

Basically, there are no embedded documents (the stuff between the curly {}), within another document. In the graphic below, you can see that the _id of the user connects all three documents (user, contact, access) together.

data-model-normalized

In general, normalized data models should be used when:

  • embedding results in duplication of data, but would not provide sufficient read performance advantages to outweigh the implications of the duplication.
  • to represent more complex many-to-many relationships.
  • to model large hierarchical data sets.

Embedded data models allow applications to store related pieces of information in the same database record. As a result, applications may need to issue fewer queries and updates to complete common operations.

Basically, there are embedded documents (the stuff between the curly {}), within another document. In the graphic below, you can see that there are additional documents (contact, access) included into the main document.

data-model-denormalized

In general, embedded data models should be used when:

Duncan Leung

Front End Developer at iHerb.com

Irvine, CA

Subscribe to Duncan Leung: Javascript and Front End Development

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!