Explore Developer Center's New Chatbot! MongoDB AI Chatbot can be accessed at the top of your navigation to answer all your MongoDB questions.

Join us at AWS re:Invent 2024! Learn how to use MongoDB for AI use cases.
MongoDB Developer
MongoDB
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
MongoDBchevron-right

A Summary of Schema Design Anti-Patterns and How to Spot Them

Lauren Schaefer, Daniel Coupal3 min read • Published Feb 12, 2022 • Updated Oct 01, 2024
MongoDBSchema
Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
We've reached the final post in this series on MongoDB schema design anti-patterns. You're an expert now, right? We hope so. But don't worry—even if you fall into the trap of accidentally implementing an anti-pattern, MongoDB Atlas can help you identify it.
It's a trap

The Anti-Patterns

Below is a brief description of each of the schema design anti-patterns we've covered in this series.
If you'd like to learn more about each of the anti-patterns, check out this YouTube playlist.

Building Your Data Modeling Foundation

Now that you know what not to do, let's talk about what you should do instead. Begin by learning the MongoDB schema design patterns. Ken Alger and Daniel Coupal wrote a fantastic blog series that details each of the 12 patterns. Daniel also co-created a free MongoDB University Course that walks you through how to model your data.
Once you have built your data modeling foundation on schema design patterns and anti-patterns, carefully consider your use case:
  • What data will you need to store?
  • What data is likely to be accessed together?
  • What queries will be run most frequently?
  • What data is likely to grow at a rapid, unbounded pace?
The great thing about MongoDB is that it has a flexible schema. You have the power to rapidly make changes to your data model when you use MongoDB. If your initial data model turns out to be not so great or your application's requirements change, you can easily update your data model. And you can make those updates without any downtime! Check out the Schema Versioning Pattern for more details.
If and when you're ready to lock down part or all of your schema, you can add schema validation. Don't worry—the schema validation is flexible too. You can configure it to throw warnings or errors. You can also choose if the validation should apply to all documents or just documents that already pass the schema validation rules. All of this flexibility gives you the ability to validate documents with different shapes in the same collection, helping you migrate your schema from one version to the next.

Spotting Anti-Patterns in Your Database

Hopefully, you'll keep all of the schema design patterns and anti-patterns top-of-mind while you're planning and modifying your database schema. But maybe that's wishful thinking. We all make mistakes.
Oh my God. I am part of the problem
If your database is hosted on MongoDB Atlas, you can get some help spotting anti-patterns. Navigate to the Performance Advisor (available in M10 clusters and above) or the Data Explorer (available in all clusters) and look for the Schema Anti-Patterns panel. These Schema Anti-Patterns panels will display a list of anti-patterns in your collections and provide pointers on how to fix the issues.
The Schema Anti-Patterns panel in the Atlas Data Explorer shows one issue found: use case-insensitive indexes.
The Schema Anti-Patterns panel in the Atlas Data Explorer shows one issue found: use case-insensitive indexes.
To learn more, check out Marissa Jasso's blog post that details this handy schema suggestion feature or watch her demo below.

Summary

Every use case is unique, so every schema will be unique. No formula exists for determining the "right" model for your data in MongoDB.
Give yourself a solid data modeling foundation by learning the MongoDB schema design patterns and anti-patterns. Then begin modeling your data, carefully considering the details of your particular use case and leveraging the principles of the patterns and anti-patterns.
So, get pumped, have fun, and model some data!
Do it. Fierce. Power
When you're ready to build a schema in MongoDB, check out MongoDB Atlas, MongoDB's fully managed database-as-a-service. Atlas is the easiest way to get started with MongoDB and has a generous, forever-free tier.
Check out the following resources for more information:

Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
This is part of a series
MongoDB Schema Design Anti-Patterns
More in this series
Related
Article

7 Things I Learned While Modeling Data for YouTube Stats


Oct 01, 2024 | 13 min read
Tutorial

MongoDB Network Compression: A Win-Win


Aug 13, 2024 | 6 min read
Article

How to Secure MongoDB Data Access with Views


Apr 07, 2023 | 4 min read
Tutorial

Getting Started with Backend Development in Kotlin Using Spring Boot 3 & MongoDB


Feb 21, 2023 | 6 min read
Table of Contents