Simple queries that run for hours

That is a big red flag to me. In MongoDB, many parts have what is so-called “yield point”. That is, if a process is waiting for something, it will yield control to other processes to go ahead. Usually, this yield point is when it’s waiting for e.g. disk access. Millions of yields seems to indicate that the disk cannot serve data fast enough, so the server is left twiddling its thumbs waiting.

An indexed query in an overworked system wouldn’t be fast as well :slight_smile: it’ll still be generally faster than a collection scan though.

What I’m guessing happened is that the server is way overloaded so it just cannot reply in time. When a query cannot be returned for hours, it may be a particulary bad combination of bad situations. It will be worse if the server is also shared with other resource-intensive processes, e.g. another MongoDB server, or an application server.

The easiest way to mitigate this is to provision larger instances for the overworked server. Another method is to ensure that the query is efficient (e.g. number of returned documents vs. number of index scan is close to 1:1). Having said that, there’s really no cure if the hardware is incapable of doing the work it’s being asked to do :slight_smile:

Best regards
Kevin