Skip to main content

馃摌 Desired Schema in MongoDB

Since MongoDB is a document database, you have more flexibility in how you model your data. When migrating from a relational database to MongoDB, it's important to consider how your data is accessed, and model the data such that data that is frequently accessed together is stored together by using embedded documents and arrays.

The following screenshot shows the MongoDB schema we will be creating in this lab.

Screenshot of the connect modal

A few key points:

  • Books will contain an array of authors with author id and name for fast retrieval. This is using the Extended Reference pattern to reference a separate collection (Authors) but having in books enough information aubout the author.
  • Reviews are not included in the books collection as they can grow and become an unbounded array, an antipattern in schema design.
  • An author can have several aliases. We just store those strings in an array.