Hi Jonathan Grant,
Greetings!
I understand your concern regarding the recent inability to update large documents in your Azure Cosmos DB for MongoDB instance, especially given that these operations were successful prior to March 24, 2025.
The error you are encountering, RequestEntityTooLarge (413), indicates that the server is rejecting your document because its size exceeds the allowed limit. As you mentioned, Cosmos DB has a limit of 2 MB for documents. However, the effective limit for requests can be lower due to overhead, especially when considering the JSON representation of the document. The BSON size may be smaller, but the JSON representation can be larger due to encoding.
Here are a few steps you might consider to address this problem:
- Activate the EnableMongo16MBDocumentSupport capability for your Azure Cosmos DB account. This can be done via the Azure Portal under the Features tab or programmatically by adding the capability to your account settings. Remember, this change will only affect new collections created after enabling the feature. To know more about this, please refer to these documents https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/how-to-configure-capabilities https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/feature-support-50
- Consider optimizing your document structure to reduce its size. Break down your large document into smaller, more manageable pieces, removing unnecessary fields or data. This can help you stay within the size limits and avoid the 413 error.
- If possible, consider breaking your updates into smaller batches. Instead of sending a large document in one request, you could update smaller portions of the document in multiple requests.
- Compress the data before storing it in CosmosDB. This can reduce the size of your documents and help you stay within the limits.
I hope this information helps. Please do let us know if you have any further queries.