title: How to extract substring of a field in mongoDB using mongo template
body: <p>I have one field &quot;branch&quot; in a mongo collection &quot;Location&quot;. Format of branch field is something like this &quot;India.Delhi.Saket&quot; or sometimes &quot;India.Punjab&quot;. I want to extract 2nd value from each of the record and get count them by using mongo template.</p>
  <pre><code>Ex.
  
  |branch                 | branch_substring(Intermediate value)|
  |-----------------------|-------------------------------------|
  | India.Delhi.Saket     |      Delhi                          |
  | India.Punjab          |      Punjab                         |
  | India.Delhi           |      Delhi                          |
  
  This should give output as follows
  
  |branch |count|
  |-------|-----|
  |Delhi  | 2   |
  |Punjab | 1   |
  </code></pre>