Description
I was doing some testing and found out that maximum document size limits of CosmosDB seem inconsistent with the documentation:
https://learn.microsoft.com/en-us/azure/cosmos-db/concepts-limits#per-item-limits
Test SQL
- Create a Cosmos DB Core (SQL) database
- Try to insert an item of 2093334 bytes into "Items" table
- It succeeds since it is:
< 2Mb
as stated in the official documentation (link above)
- Try to insert a larger item of 2239798 bytes into the same table
- It fails with error code (413) since the item is
> 2Mb
RequestEntityTooLarge error occurred: Microsoft.Azure.Cosmos.CosmosException : Response >status code does not indicate success: RequestEntityTooLarge (413); Substatus: 0; >ActivityId: c1977df8-ec39-40b9-bd69-6e6a40ff6c00; Reason: (Message: {"Errors":["Request >size is too large"]}
Conclusion: Results match the documentation
Test MongoDB
- Create a Cosmos DB (MongoDB) database
- Try to insert an item of 2093334 bytes into "Items" collection
- It succeeds since it is
< 2Mb
- Try to insert an item of 2239798 bytes into the same collection
- It still succeeds even though it is
> 2Mb
and the documentation states differently (or I am missing something)
- Try to insert an item of 4520606 bytes into the same collection
- Still succeeds even if it is
~4.31Mb
and
- Finally, when I try to insert an item of 4526027 bytes into the same collection
- It fails with error code (413):
ERROR: MongoDB.Driver.MongoWriteException: A write operation resulted in an error. >WriteError: { Category : "Uncategorized", Code : 16, Message : "Error=16, Details='Response >status code does not indicate success: RequestEntityTooLarge (413); Substatus: 0; >ActivityId: 8f20b261-e1c5-4ca9-b4e6-6cbc5352ce7e; Reason: (Message: {"Errors":["Request >size is too large"]}
Conclusion: Results do not match the documentation
NOTE
The number of bytes was calculated in the following way:
var itemStr = JsonConvert.SerializeObject(item);
var bytes = Encoding.UTF8.GetBytes(itemStr);
Console.WriteLine($"total num of bytes: {bytes.Length}");
Regarding the successful write of a large item into MongoDB, I also verified through mongoshell that the stored document is larger than 4Mb:
Object.bsonsize(db.Items.findOne({_id:ObjectId("61dec458316798c759091aef")}))
Question
- Is there any other place in the documentation which defines these sizes differently?
- Am I not interpreting these results correctly?
Any help is much appreciated, thanks!