title: How to convert MongoDB aggregation query to Laravel MongoDB by jenssegers
body: <p>I have MongoDB collection called <strong>changes</strong> which contains following data</p>
  
  <pre><code>{
      "date" : ISODate("2014-06-09T00:00:00.000Z"),
      "field" : "ip",
      "from" : "157.11.209.123",
      "to" : "107.21.109.254"
  }
  {
      "date" : ISODate("2014-05-15T00:00:00.000Z"),
      "field" : "ip",
      "from" : "107.21.109.254",
      "to" : "157.11.209.123"
  }
  {
      "date" : ISODate("2014-06-09T00:00:00.000Z"),
      "field" : "registration",
      "from" : "Old service",
      "to" : "Some new service"
  }
  </code></pre>
  
  <p>Then I want to make typical SQL query that counts occurrences and group it by <code>field</code>. So, I've created query in MongoDB</p>
  
  <pre><code>db.changes.group({
      "key": {
          "field": true
      },
      "initial": {
          "count": 0,
      },
      "reduce": function(obj, prev) {
              prev.count++;
      },
  });
  </code></pre>
  
  <p>It works fine but <strong>how can I convert it to works with Laravel 4</strong>? I am using jenssegers/laravel-mongodb to communicate with mongo server. </p>
  
  <p>In addition, I have more conditions in query, which I've removed to make my question looks more clearly, so I'm looking for solution to convert exactly that query into laravel, not other possible solutions :).</p>