title: Mongo aggregates: sum the number of bytes of BinData field
body: <p>I have a collection which contains a BinData. Here is an example doc :</p>
  
  <ul>
  <li>_id: int</li>
  <li>origLength: int (uncompressed size)</li>
  <li>uploadDate: ISODate</li>
  <li>data: (compressed data at application level)</li>
  </ul>
  
  <p>I want to perform some size check.</p>
  
  <p>I'm able to sum the uncompressed size, I can see the mongo db size. But I have no obvious way to count the total size of the data field. I can't find any aggregate function that return the BinData size.</p>
  
  <pre><code>db.passage.aggregate([{
    $group: {
        _id: 1, 
        count:{$sum : 1}, 
        totalBytes : {$sum : "$origLength"}, 
        compressedSize: {$sum : $XXX("$data")}}
    }
  ]);
  </code></pre>