If you have a huge collection, with maybe 1,000,000 documents in it, and you call, for example, Document.unscoped.any?, the whole collection will be loaded in memory.
The main reason why I see this as a bug, is that the issue is not present in 5.1.4. I am not sure what exactly happens, but 5.1.4 will instantly return with the correct value. Unfortunately, it is not the case anymore with 5.1.5.