title: MongoDB aggregation pipeline analogue for SQL query with substr operation
body: <p>MongoDB equivalent for</p>
  
  <pre><code>SELECT state, SUM(pop) AS totalPop
  FROM zipcodes
  GROUP BY state
  HAVING totalPop &gt;= (10*1000*1000)
  </code></pre>
  
  <p>is</p>
  
  <pre><code>db.zipcodes.aggregate( [
     { $group: { _id: "$state", totalPop: { $sum: "$pop" } } },
     { $match: { totalPop: { $gte: 10*1000*1000 } } }
  ] )
  </code></pre>
  
  <p>How can I get MongoDB equivalent for SQL query where <code>substr</code> operation is involved</p>
  
  <pre><code>SELECT substr(state,0,3), SUM(pop) AS totalPop
  FROM zipcodes
  GROUP BY substr(state,0,3)
  HAVING totalPop &gt;= (10*1000*1000)
  </code></pre>