- 
    Type:
Improvement
 - 
    Resolution: Unresolved
 - 
    Priority:
Major - P3
 - 
    None
 - 
    Affects Version/s: None
 - 
    Component/s: Aggregation Framework
 
- 
        Query Execution
 - 
        (copied to CRM)
 - 
        None
 
- 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 
The explain output of the $lookup stage doesn't show any information about the query that would be executed on the "from" collection. This can lead to confusion about whether or not $lookup is using an index when the document source cursor on the collection that the "aggregate" command was run on is performing a collection scan.
Original description
Lookup don't use indexes. Here is the test code:
db.goods.drop();
db.persons.drop();
db.goods_persons.drop();
db.goods.insert({'id': 1, 'name': 'good1'});
db.goods.insert({'id': 2, 'name': 'good2'});
db.persons.insert({'id': 1, 'name': 'john'});
db.persons.insert({'id': 2, 'name': 'tom'});
db.goods_persons.insert({'good': 1, 'person': 1});
db.goods_persons.insert({'good': 2, 'person': 1});
db.goods_persons.insert({'good': 1, 'person': 2});
//create all probably indexes
db.goods.ensureIndex({'id':1});
db.persons.ensureIndex({'id':1});
db.goods_perons.ensureIndex({'good':1});
db.goods_perons.ensureIndex({'person':1});
db.goods.ensureIndex({'goods_persons.person':1});
db.goods.ensureIndex({'goods_persons.good':1});
//get buyers
db.goods.aggregate(
[
    {$lookup:{
        from: "goods_persons",
        localField: "id",
        foreignField: "good",
        as: "goods_persons"
    }},
    {$match:{
        "goods_persons.person": 1
    }}
], {'explain': true}); //COLLSCAN   -  index not used
- is related to
 - 
                    
SERVER-50246 $unionWith explain loses information from any stages in sub-pipeline which get absorbed into cursor stage
-         
 - Closed
 
 -         
 
- related to
 - 
                    
SERVER-26789 Logging for $lookup less complete in 3.4 than 3.2
-         
 - Backlog
 
 -         
 - 
                    
COMPASS-7062 Query Performance Explain Summary for Aggregation Pipelines with $lookup is inaccurate with pre-SBE Execution Plans
-         
 - Backlog
 
 -         
 - 
                    
SERVER-53762 Report aggregate execution stats in explain for the inner side of $lookup
-         
 - Closed
 
 -         
 - 
                    
SERVER-88883 Report 'indexesUsed' for $lookup over sharded collections
-         
 - Needs Scheduling
 
 -