Home > front end >  MongoDB object size insertion issue C#
MongoDB object size insertion issue C#

Time:12-02

My problem is we are trying to insert a document into MongoDB and it seems to exceed the size limit of 16 MB. Now, we can debug and see what aggregates to the complete object itself but I don't know a way to see what part of the nested document amounts to the large file size in C#.

Does anyone know a way to achieve this?

Thanks in advance.

/Per

CodePudding user response:

MongoDB stores all data as JSON documents. And 16MB limit is counted as a trimmed JSON file without unnecessary indentation.

To get the same result parse your object to JSON using MongoDB serializer or use an external one like Json.NET.

Then inspect this JSON document or do some computation on it to know how many characters are in each part of the document and act accordingly to your architecture to reduce this document to below the limit or...

...don't use MongoDB to store it. Store object data as a system file and in mongo store file location that can be requested separately.

CodePudding user response:

Mongo provides a way to work with documents bigger than 16 MB called gridfs with some restrictions though. In 2 words, it splits your input document into chunks and manages work with it. To get size of entity after serialization, you can try this:

var byteArrayLength = new TestEntity().ToBson().Length;
  • Related