My original answer was inaccurate, I didn't read properly.
So my question is: Is it possible to set up some kind of partial index so queries would in first place search inside keys that have indexes, and than inside those withought them?
MongoDB will already do this but you might have a problem in the selectivity, format and size of d
and the document as a whole.
Even when MongoDB has filtered c
through the index it will need to ScanObjects
the actual data, paging the document in.
The selectivity of d
could be such that you are returning a lot of documents from the c
clause and causing a huge scan for d
.
So these factors together could be making your query slower.
The best way to slove this normally is to not use a partial index here and instead just make a full compound index.