19

I've been looking for a authoritative source of azure cosmosdb limits by I can't find one. In particular, I need to know the size limits for a individual item.

Newbie
  • 7,031
  • 9
  • 60
  • 85

4 Answers4

23

The maximum size of a document today is 2MB.

https://learn.microsoft.com/en-us/azure/cosmos-db/documentdb-resources#documents

Don Branson
  • 13,631
  • 10
  • 59
  • 101
Jesse Carter
  • 20,062
  • 7
  • 64
  • 101
  • 6
    is there a way to know the size of your document? – Kevin Cohen Nov 28 '17 at 23:30
  • 2
    It is actually a size of serialized JSON – amuliar Aug 06 '18 at 11:43
  • 2
    @amuliar But 2mb gzipped? With no whitespace? UTF-8? etc. – ruffin Aug 30 '18 at 17:47
  • 2
    [Possible answer](https://stackoverflow.com/a/46828081/1028230): "*If you get (or query) a document, you can then look at the headers that come back, specifically `x-ms-resource-usage`, which will contain a `documentsSize` attribute (representing a document's size in kb).*" – ruffin Mar 19 '19 at 13:14
  • 1
    Documentation has been updated and now, quotas can be found here: https://learn.microsoft.com/en-us/azure/cosmos-db/concepts-limits#per-item-limits – kevin Apr 19 '21 at 09:56
7

So this is one of those things that always annoys me about documentation.
Sure it's 2MB, but by who's measuring stick.

TLDR: Between 2,090,014 and 2,100,014 when Encoding.UTF8.GetByteCount(doc) or Encoding.ASCII.GetByteCount(doc)

To get there I set up the following code:

 for (int i = 10; i < 10000; i++)
        {
            var docItem = new TestItem(new string('A', i * 10000));
            string doc = JsonConvert.SerializeObject(docItem);
            log.LogInformation(" ");
            log.LogInformation(" -------------------------------------------------------------------------------------------------------------------------------------");
            log.LogInformation($" -------------------------------------------------        Doc Size = {i*10000 }       --------------------------------------------------");
            log.LogInformation(" -------------------------------------------------------------------------------------------------------------------------------------");
            
            log.LogWarning($"UTF7 - {Encoding.UTF7.GetByteCount(doc)}");
            log.LogWarning($"UTF8 - {Encoding.UTF8.GetByteCount(doc)}");
            log.LogWarning($"UTF32 - {Encoding.UTF32.GetByteCount(doc)}");
            log.LogWarning($"Unicode - {Encoding.Unicode.GetByteCount(doc)}");
            log.LogWarning($"Ascii - {Encoding.ASCII.GetByteCount(doc)}");
            log.LogInformation(" -------------------------------------------------------------------------------------------------------------------------------------");
            log.LogWarning($"UTF7 - {ASCIIEncoding.UTF7.GetByteCount(doc)}");
            log.LogWarning($"UTF8 - {ASCIIEncoding.UTF8.GetByteCount(doc)}");
            log.LogWarning($"UTF32 - {ASCIIEncoding.UTF32.GetByteCount(doc)}");
            log.LogWarning($"Unicode - {ASCIIEncoding.Unicode.GetByteCount(doc)}");
            log.LogWarning($"Ascii - {ASCIIEncoding.ASCII.GetByteCount(doc)}");
            try
            {
                await cosmosStore.CreateDocumentAsync(docItem);
            }
            catch (Exception e)
            {
                log.LogWarning(e.Message + "Caught");
            }
        }

And here's where it broke: enter image description here

A.Rowan
  • 1,460
  • 2
  • 16
  • 20
1

Update: increasing the max size to 16 MB is now possible. https://devblogs.microsoft.com/cosmosdb/larger-document-sizes-unique-index-improvements-expr-support-in-azure-cosmos-db-api-for-mongodb/

Bobbito
  • 11
  • 1
0

The max allowable document size is 2 MB. This is fixed for Azure Cosmos DB for NOSQL API account

If it Exceeds you face 413 error --> 413 Entity too large  The document size in the request exceeded the allowable document size for a request.

If your Environment is already in Production we still suggest reducing the document size as a solution. You can Reduce the document size/ Re model your data

More Info: Azure Cosmos DB service quotas | Microsoft Learn

https://learn.microsoft.com/en-us/azure/cosmos-db/concepts-limits#per-item-limits

Additional Information:

For Azure Cosmos DB for API for MongoDB If your Azure Cosmos DB account is Mongo DB API , the limit is 2 MB but

  • There is a preview feature and please be noted that this is not recommended for prod environment: There is a preview feature to set 16MB limit per document in API for MongoDB.

Ref:

However, it’s in preview and not recommended for Production environments. There’s no ETA when it will be GA.

Srinathji
  • 159
  • 1
  • 4
  • 14