Chapter 9. Application Design
This chapter covers designing applications to work effectively with MongoDB. It discusses:
Schema design considerations
Trade-offs when deciding whether to embed data or to reference it
Tips for optimization
Consistency considerations
How to migrate schemas
How to manage schemas
When MongoDB isn’t a good choice of data store
Schema Design Considerations
A key aspect of data representation is the design of the schema, which is the way your data is represented in your documents. The best approach to this design is to represent the data the way your application wants to see it. Thus, unlike in relational databases, you first need to understand your queries and data access patterns before modeling your schema.
Here are the key aspects you need to consider when designing a schema:
- Constraints
You need to understand any database or hardware limitations. You also need to consider a number of MongoDB’s specific aspects, such as the maximum document size of 16 MB, that full documents get read and written from disk, that an update rewrites the whole document, and that atomic updates are at the document level.
- Access patterns of your queries and of your writes
You will need to identify and quantify the workload of your application and of the wider system. The workload encompasses both the reads and the writes in your application. Once you know when queries are running and how frequently, you can identify the most common queries. These are the queries you need to design your ...
Get MongoDB: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.