title: how to aggregate group in mongoengine python
body: <p>I am trying to aggregate <code>group</code> in <code>MongoDB</code>.</p>
  
  <p>We are using <code>Python</code>, <code>django</code>, <code>Rest framework</code> and <code>Mongoengine</code>.</p>
  
  <p>This is how my model looks like:</p>
  
  <pre><code>class TestSnapshot(EmbeddedDocument):
      identifier = StringField()
  name = StringField()
  created = DateTimeField(
      default = datetime.datetime.now)
  
  class Test(Document):
      agreement = ReferenceField(Agreement)
  history = ListField(EmbeddedDocumentField(TestSnapshot))
  created = DateTimeField(
      default = datetime.datetime.now)
  </code></pre>
  
  <p>In my view:</p>
  
  <pre><code>test = models.Test.objects.filter(agreement__in = agreements).aggregate([{
      "$unwind": "$created"
  }, {
      "$group": {
      "_id": "$created"
      }
  }])
  print test
  </code></pre>
  
  <p>But I got a trackback like this:</p>
  
  <pre><code>OperationFailure: command SON([('aggregate', u 'test'), ('pipeline', [{
      '$match': {
          'agreement': {
              '$in': [ObjectId('558b150a89f4ad3f33ebb8ae')]
          }
      }
      },
      [{
      '$unwind': '$created'
      }, {
      '$group': {
          '_id': '$created'
      }
      }]
  ]), ('cursor', {})]) on namespace noq.$cmd failed: exception: pipeline element 1 is not an object
  </code></pre>
  
  <p>What am I doing wrong? I am new to <code>python</code> with <code>mongo</code>.
   Thanks for helping :)</p>
  
  <p>Best regards,
  Johnny</p>