title: MongoDb and Golang - Match before Group
body: <p>I am trying to <strong>$match</strong> my list of <strong>Event</strong> before to <strong>$group</strong> them but it does not work. If I remove the first <code>$match</code>, I get results.</p>
  
  <p>The <strong>Event</strong> has a <strong>start_date</strong> property.</p>
  
  <p>I need to get the IDs of the duplicated events that start from 2 months to now. A duplicated event is an event that is a the same location at same hour.</p>
  
  <pre><code>    // Create the pipeline
      pipeline := []bson.M{
          bson.M{
              "$match": bson.M{
                  "start_date": bson.M{"$gt": time.Now().AddDate(0, -2, 0)},
              },
          },
          bson.M{
              "$group": bson.M{
                  "_id": bson.M{
                      "_location_id": "$_location_id",
                      "start_date":   "$start_date",
                  },
                  "docs":  bson.M{"$push": "$_id"},
                  "count": bson.M{"$sum": 1},
              },
          },
          bson.M{
              "$match": bson.M{
                  "count": bson.M{"$gt": 1.0},
              },
          },
      }
  </code></pre>
  
  <p>Am I missing something ?</p>
  
  <p>I checked in database and I do have events that have a <code>start_date</code> matching my criteria, with that request <code>db.events.find({}).sort({ "start_date": -1}).limit(1);</code> and that one <code>db.events.find({"start_date": { "$gt": ISODate("2019-05-16T00:00:00.0Z")}}).limit(1)</code></p>
  
  <p>Version : MongoDB shell version v3.4.6</p>