title: MongoDB aggregate/group/sum query translated to pymongo query
body: <p>I have a set of entries in the <code>goals</code> collection that looks like this:</p>
  
  <pre><code>{"user": "adam", "position": "attacker", "goals": 8}
  {"user": "bart", "position": "midfielder", "goals": 3}
  {"user": "cedric", "position": "goalkeeper", "goals": 1}
  </code></pre>
  
  <p>I want to calculate a sum of all goals. In MongoDB shell I do it like this:</p>
  
  <pre><code>&gt; db.goals.aggregate([{$group: {_id: null, total: {$sum: "$goals"}}}])
  { "_id" : null, "total" : 12 }
  </code></pre>
  
  <p>Now I want to do the same in Python using pymongo. I tried using both <code>db.goals.aggregate()</code> and <code>db.goals.group()</code>, but no success so far.</p>
  
  <p>Non working queries:</p>
  
  <pre><code>&gt; query = db.goals.aggregate([{"$group": {"_id": None, "total": {"$sum": "$goals"}}}])
  {u'ok': 1.0, u'result': []}
  
  &gt; db.goals.group(key=None, condition={}, initial={"sum": "goals"}, reduce="")
  SyntaxError: Unexpected end of input at $group reduce setup
  </code></pre>
  
  <p>Any ideas how to do this?</p>