0
{
  field_1: [
    {A: 1, ...}
    {A: 10, ...}
    {A: 2, ...}
  ]
}

What if field_1 has 10s of 1000s of subdocuments in its array?

What kind of query performance would be negatively affected? And why?

What if the subdocuments are multi key indexed?

  • I am not sure if this is technically possible due to the [16MB document size limit](https://www.mongodb.com/docs/manual/core/document/#document-size-limit) – ray Apr 21 '22 at 15:26
  • ok, let's assume that it will be less than 16MB. So maybe assume 100s of 100s of subdocs instead of millions – Bear Bile Farming is Torture Apr 21 '22 at 15:28
  • 1
    big documents in general, take longer time be loaded in memory, for example in 1 update, you have to load it and then write back. so in general i think its best to not have big documents of MBs. – Takis Apr 21 '22 at 19:01
  • @Takis, but how to know at which stage are documents loaded into memory? For example, at the `$match` where filters are applied against indexed fields would documents be loaded into memory? – Bear Bile Farming is Torture Apr 21 '22 at 20:14
  • 1
    big documents and collection scan is expected to be slow, but if index is used big documents cause much less problems, But still every document that will be fetched to update for example it will cost more, even if you update 1 field only, the cost will be bigger. An array to have 1000s members is not too many, it would be like kb. But if you put like 100k you go MBs. I think best way is to test it and see if you have perfomance problems – Takis Apr 21 '22 at 20:22

1 Answers1

0

If field_1 has a million subdocuments then it overload the stack in runtime and compiler will not be able to process that amount of data, it will result in crashing your code.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 22 '22 at 02:34