Suspect that $exists is causing a memory leak

Well then that’s ALL the documents (20GB) minus 1 doc. You don’t need an index for that. It’s a collection scan of the entire collection. An index won’t help. It also means that the entire collection will be in the cache so you need a large LARGE one… Are you sure that you need 20GB of data in your client?

If 99.9% of your docs don’t have this field, then it’s not worth it. Just create an index for whatever other query you want to support and just add the {meta: {$exists: false}} in your queries. They will use the indexes that actually speed up the research, fetch the docs and then check if one doc eventually has meta in it and can be eliminated. It’s not worth adding the meta at the end of every index because it’s going to store a lot of null values (and take a lot of space) for almost zero extra speed.

Also, why is that weird document in that collection? Can’t you remove it from here and put it in another collection with other similar documents?

From what I see, your cluster is starving for RAM. A database (any on the market) should never swap.

CF the production notes about swap: https://docs.mongodb.com/manual/administration/production-notes/#swap

Cheers,
Maxime.

1 Like