ReplaceOneAsync upsert exception: Request size is too large


I’m using MongoDB.Driver 2.10.3 with a .NET core 3 mvc app and Azure document db emulator / Azure cloud db. It works for the most part but I hit the following exception when the document reaches 2-3 MB doing a ReplaceOneAsync request with upsert=true:

MongoDB.Driver.MongoCommandException: ‘Command update failed: Message: {“Errors”:[“Request size is too large”]}
ActivityId: 7caef9ed-0000-0000-0000-000000000000, Request URI: /apps/DocDbApp/services/DocDbServer14/partitions/a4cb495a-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats:
RequestStartTime: 2020-04-19T00:03:47.1617890Z, RequestEndTime: 2020-04-19T00:03:47.1617890Z, Number of regions attempted:1
, SDK: Microsoft.Azure.Documents.Common/2.9.2.’

Is there any work around for it apart from splitting to smaller documents ? This isn’t ideal for me as I have base 64 encoded images I want to store which are several MB in size.

Appreciate any help with this. Thanks

Hi Paul,

Azure’s Cosmos DB includes an emulation of the MongoDB API with a distinct server implementation: features, behaviour, and limits will differ from the reported MongoDB server version. Questions on Cosmos are better posted on Azure’s community support channels.

CosmosDB currently has a 2MB document limit (versus MongoDB’s 16MB limit), so you will have to change your approach to store larger documents in Cosmos.

You could also consider using MongoDB Atlas on Azure instead, which runs MongoDB Enterprise with the standard 16MB document size limit.