What happens if a document grows beyond the 16MB limit due to an 'Embedding' design choice?
Trap 1: MongoDB automatically moves the overflow data to a new document.
MongoDB does not automatically move data between documents. If a write operation would push a document over 16MB, the entire write fails. The application is responsible for managing document size and ensuring that the schema is designed to prevent documents from reaching the hard limit defined by the BSON specification.
Trap 2: The engine automatically compresses the document to fit.
While WiredTiger uses compression for disk storage, the BSON limit applies to the uncompressed document in memory. Compression is a storage-level feature that does not allow you to bypass the 16MB limit, which is defined at the logical document level, not the physical disk storage level. You cannot exceed this limit.
Trap 3: The document is split into two, and the original ID is shared.
MongoDB does not have a native 'split' mechanism for documents. Every document must have a unique _id. If you need to break up data, you must implement the application logic to move data to a separate collection or a different document structure; the database will not do this for you.
- A
MongoDB automatically moves the overflow data to a new document.
Why it fails: MongoDB does not automatically move data between documents. If a write operation would push a document over 16MB, the entire write fails. The application is responsible for managing document size and ensuring that the schema is designed to prevent documents from reaching the hard limit defined by the BSON specification.
- B
The write operation will fail.
The 16MB limit is a hard architectural constraint. If an update causes a document to exceed this size, the database rejects the change and returns an error. This is why careful schema modeling, such as using the Subset pattern or Referencing, is essential for datasets that grow over time.
- C
The engine automatically compresses the document to fit.
Why it fails: While WiredTiger uses compression for disk storage, the BSON limit applies to the uncompressed document in memory. Compression is a storage-level feature that does not allow you to bypass the 16MB limit, which is defined at the logical document level, not the physical disk storage level. You cannot exceed this limit.
- D
The document is split into two, and the original ID is shared.
Why it fails: MongoDB does not have a native 'split' mechanism for documents. Every document must have a unique _id. If you need to break up data, you must implement the application logic to move data to a separate collection or a different document structure; the database will not do this for you.