What is the size limit of a cosmosdb item?

后端 未结 2 1633
温柔的废话
温柔的废话 2021-01-17 15:13

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.

相关标签:
2条回答
  • 2021-01-17 15:20

    The maximum size of a document today is 2MB.

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

    0 讨论(0)
  • 2021-01-17 15:37

    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:

    0 讨论(0)
提交回复
热议问题