title: mongodb conditional stages or conditional pipeline in aggregation
body: <p>there's the prices collection.</p>
  
  <pre><code>[{  
     "_id":"...683d",
     "brandId":"...f31c",
     "model":"N5",
     "pwId":"...1b67",
     "number":50
  }, {  
     "_id":"...683e",
     "brandId":"...f31c",
     "model":"base",
     "pwId":"...1b67",
     "number":40
  }, ...]
  </code></pre>
  
  <p>there's the items collection.</p>
  
  <pre><code>[{  
     "_id":"...31aa",
     "pwId":"...1b67",
     "brandId":"...f31c",
     "model":"abc",
     "series": "N5",
     "bms": "yyn"
  }, ...]
  </code></pre>
  
  <p>I'd like to get the price of items and the steps are:</p>
  
  <ol>
  <li>check <code>item.bms</code>, if <code>bms === 'yyn'</code>, use sub-pipeline-a, otherwise, use sub-pipeline-b;</li>
  <li>let's look at sub-pipeline-a, sub-pipeline-b could be similar.
  2.1 match price with three conditons, <code>pwId + brandId + model</code>, if found, go no further;
  2.2 if not found, try <code>pwId + brandId + series</code>(<code>item.series</code> as <code>price.model)</code>, if found, go no further;
  2.3 if still not found, try <code>pwId + brandId + 'base'</code>(<code>'base'</code> as <code>price.model</code>);</li>
  <li>combine the result of both sub-pipeline-a and sub-pipeline-b.</li>
  </ol>
  
  <p>For step 1, I'm using a <code>$facet</code> stage. For step 2.1 through 2.3, I'm running 3 <code>$lookup</code>s one after another, which is obviously a waste of resources.</p>
  
  <p>How to decide whether to run 2.2 based on result of 2.1?</p>