title: How can I use same MongoDb pipeline for two queries with common first stage?
body: <p>I have 2 queries which I use the aggregate()  pipeline </p>
  
  <ol>
  <li>[filter,sort1,A,B,C]</li>
  <li>[filter,sort2,a,b,c]</li>
  </ol>
  
  <p>Is it possible that I use the first stage of the pipeline for both the queries? It will also make the two queries transactional if the first stage is common. </p>
  
  <p>I am using the aggregate() function and 4 stages. Similarly, I have 1 more query where I just have to get an aggregate count after the initial filter.</p>
  
  <p>I want both the queries to have consistent data as my database is updating quickly. So I would want to use only 1 pipeline initially for the first stage. </p>
  
  <pre class="lang-py prettyprint-override"><code>collection.aggregate([initialFilter,sortInitial,group,sortFinal])
  </code></pre>
  
  <p>I am using pymongo client.</p>
  
  <p>Also how to make 2 queries transactional/atomic in pymongo?</p>