When a document has reached 16mb, when do you insert the new documents in the same collection and when in another collection?

I have studied relational databases in college. But now I am building a data model using MongoDB. And the concept of handling the scenario where a document exceeds a limit is new to me.

A collection is supposed to conform to a schema. So if I insert the new overflow documents into the same collection, those new over documents are somewhat distinct from the rest?

What do we call these situations and are there any documentations on them?

Hey @Big_Cat_Public_Safety_Act,

Think of a collection as a table. But unlike relational databases, documents in the same collection can have different fields which is what we call having a flexible scheme. You can read more in the SQL to MongoDB mapping chart.

Coming back to the question, you cannot go around the 16 MB BSON size limitation for a document. Unlike SQL’s normal form schema design, MongoDB’s schema design is based on your application’s access pattern. If you hit the 16 MB limit, it usually means that the design is probably not optimal, since such large documents will be detrimental to performance, difficult to update, etc. Typically, it’s better to have a lot of small documents as opposed to a few gigantic documents. You can read more about it and look at a few examples too in Data Model Design and Data Model Examples and Patterns.

Regards,
Satyam

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.