Is it good practice to keep document size large?

Hello Everyone,

I have a app where I store users daily nutrition diary.

Currently I have array of objects that looks like this:

days = [
  {name: "Monday", meals: {...}}
  {name: "Tuesday", meals: {...}}
  {name: "Wednesday", meals: {...}}
  {name: "Thursday", meals: {...}}
]

I am only planning to keep 7 to 10 days in the array so it’s not going to infinitely scale, however each day can be up to 300kb, so that would make total document size of about 1-3mb.

So I just wanted to know if its a good practice to keep all this information in single document or would it be better to put each day in a subcollection?

I really wanted to know this, so hopefully someone helps me.

It depends. I would start by reading

There is a lot of information in the above, that will help you for your use-case.

Hi @Lukas_Visinskis,

In addition to @steevej’s recommendation I suggest reviewing the following two series of schema design posts:

The anti-patterns series in particular talks about some of the performance consequences of large documents. Large documents will occupy more RAM and may use more network bandwidth if you are retrieving unused fields in your queries.

For example, updating a single field in a 3MB document will require fetching the whole document into server memory to apply the update. This may be fine if all of the fields in the document are commonly used and updated with similar frequency, but smaller documents could be more efficient.

The Atlas documentation also includes a recommendation to Reduce the Size of Large Documents for similar reasons:

If your most frequent queries are for documents that contain much more information than you need for that query, consider restructuring your schema with smaller documents using references to additional collections. By breaking up your data into more collections and using smaller documents for frequently accessed data, you reduce the overall size of the working set and improve performance.

Regards,
Stennie

1 Like