title: $lookup in aggregation is very slow
body: <p>I am using <code>$lookup</code> to join two collections for counting, but <code>executionStats</code> shows that the query is very slow (500+ms per query for a single lookup). Here is the collection size:</p>
  <pre><code>&gt; db.visit.find({}).count()
  8174
  &gt; db.links.find({}).count()
  89
  </code></pre>
  <p>Here is the lookup strage for the aggregation:</p>
  <pre><code>&gt; db.visit.explain('executionStats').aggregate([{&quot;$lookup&quot;: {from: &quot;links&quot;, localField: &quot;alias&quot;, foreignField: &quot;alias&quot;, as: &quot;url&quot;}}])
  </code></pre>
  <p>results in:</p>
  <pre><code>{
      &quot;stages&quot;: [
          {
              &quot;$cursor&quot;: {
                  &quot;queryPlanner&quot;: {
                      &quot;plannerVersion&quot;: 1,
                      &quot;namespace&quot;: &quot;redir.visit&quot;,
                      &quot;indexFilterSet&quot;: false,
                      &quot;parsedQuery&quot;: {
  
                      },
                      &quot;queryHash&quot;: &quot;8B3D4AB8&quot;,
                      &quot;planCacheKey&quot;: &quot;8B3D4AB8&quot;,
                      &quot;winningPlan&quot;: {
                          &quot;stage&quot;: &quot;COLLSCAN&quot;,
                          &quot;direction&quot;: &quot;forward&quot;
                      },
                      &quot;rejectedPlans&quot;: []
                  },
                  &quot;executionStats&quot;: {
                      &quot;executionSuccess&quot;: true,
                      &quot;nReturned&quot;: 8174,
                      &quot;executionTimeMillis&quot;: 642,
                      &quot;totalKeysExamined&quot;: 0,
                      &quot;totalDocsExamined&quot;: 8174,
                      &quot;executionStages&quot;: {
                          &quot;stage&quot;: &quot;COLLSCAN&quot;,
                          &quot;nReturned&quot;: 8174,
                          &quot;executionTimeMillisEstimate&quot;: 0,
                          &quot;works&quot;: 8176,
                          &quot;advanced&quot;: 8174,
                          &quot;needTime&quot;: 1,
                          &quot;needYield&quot;: 0,
                          &quot;saveState&quot;: 9,
                          &quot;restoreState&quot;: 9,
                          &quot;isEOF&quot;: 1,
                          &quot;direction&quot;: &quot;forward&quot;,
                          &quot;docsExamined&quot;: 8174
                      }
                  }
              },
              &quot;nReturned&quot;: NumberLong(8174),
              &quot;executionTimeMillisEstimate&quot;: NumberLong(7)
          },
          {
              &quot;$lookup&quot;: {
                  &quot;from&quot;: &quot;links&quot;,
                  &quot;as&quot;: &quot;url&quot;,
                  &quot;localField&quot;: &quot;alias&quot;,
                  &quot;foreignField&quot;: &quot;alias&quot;
              },
              &quot;nReturned&quot;: NumberLong(8174),
              &quot;executionTimeMillisEstimate&quot;: NumberLong(643)
          }
      ]
  }
  </code></pre>
  <p>Why and how to fix it?</p>