# MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB) First element

- **ID:** `database/mongodb-bson-size-exceeded`
- **Domain:** database
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A BSON document exceeds MongoDB's 16MB document size limit, typically caused by inserting or updating a document with large arrays, nested data, or binary fields like GridFS chunks that exceed the maximum allowed size.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## Workarounds

1. **Use GridFS for large files: store the large data as a GridFS file instead of embedding it in a document. Example: mongofiles put large_file.bin --db mydb** (95% success)
   ```
   Use GridFS for large files: store the large data as a GridFS file instead of embedding it in a document. Example: mongofiles put large_file.bin --db mydb
   ```
2. **Reduce document size by removing unnecessary fields, splitting arrays into separate collections, or using references (e.g., store large arrays in a subcollection and link via _id).** (85% success)
   ```
   Reduce document size by removing unnecessary fields, splitting arrays into separate collections, or using references (e.g., store large arrays in a subcollection and link via _id).
   ```

## Dead Ends

- **Increasing the BSON document size limit via a configuration parameter like 'maxBsonObjectSize'** — MongoDB does not allow changing the 16MB limit; it is a hard-coded limit in the server. Attempting to set such a parameter will be ignored or cause an error. (100% fail)
- **Splitting the document into multiple smaller documents but keeping the same structure without using references** — If the application logic expects a single document, splitting may break queries; also, if the data is inherently large (e.g., a large file), splitting into separate documents may not be appropriate without using GridFS. (60% fail)
