What is the maximum size of a document in MongoDB?

The maximum size of a document in MongoDB is 16 MB (16,777,216 bytes). This limit ensures efficient memory usage and prevents documents from consuming excessive resources during operations.

Syntax

// Document structure with size limit
{
    field1: "value1",
    field2: "value2",
    // ... additional fields
    // Total document size ? 16 MB
}

Sample Data

Let us create a collection with sample documents ?

db.demo748.insertMany([
    {_id: 101, Name: "Chris", Age: 21},
    {_id: 102, Name: "Bob", Age: 20},
    {_id: 103, Name: "David", Age: 23},
    {_id: 104, Name: "Sam", Age: 19}
]);
{
    "acknowledged": true,
    "insertedIds": [101, 102, 103, 104]
}

Example

Display all documents from the collection ?

db.demo748.find();
{ "_id": 101, "Name": "Chris", "Age": 21 }
{ "_id": 102, "Name": "Bob", "Age": 20 }
{ "_id": 103, "Name": "David", "Age": 23 }
{ "_id": 104, "Name": "Sam", "Age": 19 }

Key Points

  • The 16 MB limit applies to individual documents, not collections
  • Documents exceeding this limit will cause an insertion error
  • Large files should be stored using GridFS for files over 16 MB
  • Embedded arrays and subdocuments count toward the total document size

Conclusion

MongoDB enforces a 16 MB maximum document size to maintain performance and memory efficiency. For larger data storage needs, use GridFS or consider restructuring your document design.

Updated on: 2026-03-15T03:55:38+05:30

540 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements