简体   繁体   中英

MongoDB object size insertion issue C#

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

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM