title: Split string during mongodb aggregation
body: <p>I have collection in MongoDB with documents like:</p>
  
  <pre><code>{_id : "...", ip : "0.1.10.200", item : "..."}
  </code></pre>
  
  <p><code>ip</code> is IP v4 address. 
  I need to group this data by IP. Also, I need to split ip into 4 parts and add additional fields to result from document like:</p>
  
  <pre><code>{
      "ip" : "0.1.10.200",
      "ip_part1" : "0",
      "ip_part2" : "1",
      "ip_part3" : "10",
      "ip_part4" : "200",
      "items" : [ 
       ...
      ]
  }
  </code></pre>
  
  <p>I'm using aggregation framework for grouping by <code>ip</code>. But I don't know how I can split <code>ip</code> into parts. <code>$substr</code> is not suitable because <code>ip</code> address could be:
  <code>
  "100.110.0.0"
  "1.10.100.1"
  </code>
  So I don't know start and end index for each part of IP-address.</p>
  
  <p>What is the best way to split ip into parts during aggregation?</p>