- 
    Type:
Improvement
 - 
    Resolution: Done
 - 
    Priority:
Major - P3
 - 
    None
 - 
    Affects Version/s: 3.0.3
 - 
    Component/s: Querying
 - 
    None
 
- 
        Query Optimization
 - 
        None
 
- 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 
I have a primary collection users:
{ _id: ObjectId, follow: [ObjectId], primary: ObjectId }primary field is optional in document
I have a non-sparse index:
When I try to query all followers without primary:
db.users.count(
)
it uses only follow field, fetches all these documents and then filters out documents where primary is null.
Here is a result from explain:
"winningPlan" : {
    "stage" : "COUNT", 
    "inputStage" : {
        "stage" : "FETCH", 
        "filter" : {
            "primary" : 
        }, 
        "inputStage" : {
            "stage" : "IXSCAN", 
            "keyPattern" : 
, 
            "indexName" : "follow_1_primary_1", 
            "isMultiKey" : true, 
            "direction" : "forward", 
            "indexBounds" : 
        }
    }
}
It shows 'filter' stage that absolutely not needed.
It drastically drops down a performance of an application.
I checked that if I put primary as 0 - it works fine.
The problem is query with null value.
- is duplicated by
 - 
                    
SERVER-20155 Query for null filters before index scan
-         
 - Closed
 
 -         
 
- is related to
 - 
                    
SERVER-18861 Queries matching null value should be fully covered by index
-         
 - Backlog
 
 -