title: mongodb sum length of all lists in a database
body: <p>I'm pretty new to mongo aggregations and I've been getting some relatively unhelpful errors and I haven't quite been able to find any clear examples. The short is that I have a collection <code>user_data</code>, the document is arranged like so:</p>
  
  <pre><code>{
      _id: ObjectID,
      text: [#Documents],
      username: "&lt;string&gt;",
      metadata: {&lt;fields&gt;}
  }
  </code></pre>
  
  <p>Basically, I'm looking to count the total number of documents present in this collection. The documents are all under the text field. I feel very close merging the <code>$sum</code>, and <code>$size</code> selectors, and this is what I have now:</p>
  
  <pre><code>db.user_data.aggregate([{$sum: {$size: "$text"}}])
  </code></pre>
  
  <p>Which seems at least on the right track, but running this I get this error message:</p>
  
  <pre><code>command failed: {
      "errmsg" : "exception: Unrecognized pipeline stage name: '$sum'",
      "code" : 16436,
      "ok" : 0
  } : aggregate failed at src/mongo/shell/assert.js:13
  </code></pre>
  
  <p>Any help would be very much appreciated. Again, very new to aggregations.</p>