存储在 Azure Cosmos DB 中的单个文档的大小限制是多少

What is the size limit of a single document stored in Azure Cosmos DB

我在 Azure 中有一个 MongoDB 数据库(在 Cosmos DB 帐户下注册),我在 ms docs 上读到每个存储文档的大小限制为 2MB。但是,当我尝试存储大约 1.7 MB 的图像缓冲区时,出现以下错误:

2019-11-01T00:43:14.057681416Z { MongoError: Message: {"Errors":["Request size is too large"]}
2019-11-01T00:43:14.057757320Z RequestStartTime: 2019-11-01T00:43:13.9695930Z, RequestEndTime: 2019-11-01T00:43:13.9995776Z,  Number of regions attempted:1
2019-11-01T00:43:14.057768921Z ResponseTime: 2019-11-01T00:43:13.9995776Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-centralus1-fd19.documents.azure.com:14112/apps/0806fa15-6a2d-4127-a73b-b1626ddd8af1/services/5618d8a3-dc06-4e8a-ba18-39d3b0c58add/partitions/d61f7139-78bf-423b-a4d7-747179270393/replicas/132167814077711166p/, LSN: -1, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 410, SubStatusCode: 0, RequestCharge: 0, ItemLSN: -1, SessionToken: , UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Create
2019-11-01T00:43:14.057779921Z SDK: Microsoft.Azure.Documents.Common/2.7.0
2019-11-01T00:43:14.057788121Z     at Function.create (/home/site/wwwroot/node_modules/mongodb/lib/core/error.js:44:12)
2019-11-01T00:43:14.057796322Z     at toError (/home/site/wwwroot/node_modules/mongodb/lib/utils.js:150:22)
2019-11-01T00:43:14.057804822Z     at coll.s.topology.insert (/home/site/wwwroot/node_modules/mongodb/lib/operations/common_functions.js:266:39)
2019-11-01T00:43:14.057813223Z     at handler (/home/site/wwwroot/node_modules/mongodb/lib/core/sdam/topology.js:1000:24)
2019-11-01T00:43:14.057821223Z     at wireProtocol.(anonymous function) (/home/site/wwwroot/node_modules/mongodb/lib/core/sdam/server.js:457:5)
2019-11-01T00:43:14.057829423Z     at /home/site/wwwroot/node_modules/mongodb/lib/core/connection/pool.js:408:18
2019-11-01T00:43:14.057837624Z     at process._tickCallback (internal/process/next_tick.js:61:11)
2019-11-01T00:43:14.057845624Z   driver: true,
2019-11-01T00:43:14.057853424Z   name: 'MongoError',
2019-11-01T00:43:14.057861125Z   index: 0,
2019-11-01T00:43:14.057868725Z   code: 16,
2019-11-01T00:43:14.057876326Z   errmsg:
2019-11-01T00:43:14.057886326Z    'Message: {"Errors":["Request size is too large"]}\r\n, RequestStats: \r\nRequestStartTime: 2019-11-01T00:43:13.9695930Z, RequestEndTime: 2019-11-01T00:43:13.9995776Z,  Number of regions attempted:1\r\nResponseTime: 2019-11-01T00:43:13.9995776Z, LSN: -1, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 410, SubStatusCode: 0, RequestCharge: 0, ItemLSN: -1, SessionToken: , UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Create\r\n, SDK: Microsoft.Azure.Documents.Common/2.7.0',
2019-11-01T00:43:14.057902127Z   [Symbol(mongoErrorContextSymbol)]: {} }

目前,我处于 ​​Azure for Students 订阅状态​​,并且一直在为我的所有资源使用免费套餐。我还阅读了 this documentation 中关于存储和吞吐量的内容,但我不确定我需要修改什么才能让事情正常进行。

有人可以指点一下吗?

文档的最大大小为 2 MB,无法增加。在您的情况下,您可以将图像存储在 blob 存储中,并将 url 作为 属性 附加到您正在保存的文档中,这将节省几个字节。

基于此link,最大请求大小为 2MB。

总请求包含文件大小和common requests.You could capture the request and check the size of it by using Fiddler Tool

在 Cosmos DB 中存储文档时会发生编码。我怀疑您的二进制数据在编码时(扩展其存储大小)将成为使您的文档大小远远超出预期(并超出 2MB 大小限制)的问题。

正如@sajeetharan 提到的,有其他方法可以存储二进制数据(例如 blob,在 Cosmos DB 文档中只有一个引用 uri),这将有助于减小 blob 的大小。

您的订阅类型与 Cosmos DB 的文档大小限制无关。