问题
I have a MongoDB database in Azure (registered under a Cosmos DB account) and I read on ms docs that the size limit per document stored is 2MB. However, when I try to store an image buffer that is around 1.7 MB I get the following error:
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)]: {} }
Currently, I'm on an Azure for Students
subscription and I've been using the free tier for all of my resources. I also read in this documentation on storage and throughput, but I'm not sure what I would have to modify in order to get things working.
Can someone please advise?
回答1:
The maximum size of a document is 2 MB and cannot be increased. In your case you can store the image in blob storage and attach the url as a property to the document you are saving which will save few bytes.
回答2:
There is encoding that takes place, when storing a document in Cosmos DB. I suspect your binary data, when encoded (expanding its stored size), is going to be the issue pushing your document size well beyond what's expected (and beyond the 2MB size limit).
As @sajeetharan mentioned, there are alternative ways to store your binary data (such as a blob, with only a reference uri in your Cosmos DB document), that will help reduce blob size.
The type of subscription you have has nothing to do with Cosmos DB's document size limits.
回答3:
Based on this link, Maximum request size is 2MB.
The total request contains the file size and common requests.You could capture the request and check the size of it by using Fiddler Tool.
来源:https://stackoverflow.com/questions/58653153/what-is-the-size-limit-of-a-single-document-stored-in-azure-cosmos-db