-
Type: New Feature
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
I often need to run queries of the form {a: {$ne:null}}, i.e. find documents in which the field "a" is not missing and not equal to null. As I understand it, an index on "a" will not cover this query because the index will not include documents where "a" is missing.
In these cases I find myself forced to always include a value for "a". This isn't hard to do - generally there's always some value I can reserve for this purpose (often "null" of course, but sometimes another value if "null" doesn't mean the same thing as a missing value).
It seems to me that mongo could do this for me transparently (by reserving a value to indicate "missing" and including those documents in the index). I completely understand that minimizing index size is important, and this wouldn't be appropriate in many contexts, and certainly not as a default. Nevertheless, this comes up over and over again (I've been running an expansive production environment on mongo for many years). So I think it would make an incredibly useful option when creating an index.
Apologies if I'm missing something about why this isn't feasible (or perhaps feasible but not simple) to implement, or why it's not a good idea. I tried to cover this in a bit more detail on stack overflow before submitting this request:
https://stackoverflow.com/questions/63003917
- duplicates
-
SERVER-18861 Queries matching null value should be fully covered by index
- Backlog