0PricingLogin
MongoDB Academy · Lesson

The Unbounded Array Anti-Pattern

Learners will identify when embedding leads to documents that grow without bound and refactor the schema to use references instead.

What Is an Unbounded Array?

An unbounded array is an array field inside a document that can grow indefinitely over time. If your schema design allows an array to accumulate items without any upper limit—like storing all user comments inside the user document, or all log entries inside an event document—you have an unbounded array anti-pattern. This is one of the most common MongoDB design mistakes.

The 16 MB Document Size Limit

MongoDB enforces a hard document size limit of 16 MB. An unbounded array grows that document over time. A user document that embeds all messages, all activity log entries, or all purchase history will eventually hit this ceiling. When the limit is reached, inserts fail with a BSONObjectTooLarge error, and there is no graceful way to recover without refactoring the schema.

All lessons in this course

  1. Embedding: One-to-Few Relationships
  2. Referencing: One-to-Many and Many-to-Many
  3. The Unbounded Array Anti-Pattern
  4. Schema Design Decision Framework
← Back to MongoDB Academy