title: Get percentages with MongoDB aggregate $group
body: <p>I'd like to get percentages from a group pipeline in a MongoDB aggregate.</p>
  
  <p>My data:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
      _id : 1,
      name : 'hello',
      type : 'big'
  },
  {
      _id : 2,
      name : 'bonjour',
      type : 'big'
  },
  {
      _id : 3,
      name : 'hi',
      type : 'short'
  },
  {
      _id : 4,
      name : 'salut',
      type : 'short'
  },
  {
      _id : 5,
      name : 'ola',
      type : 'short'
  }
  </code></pre>
  
  <p>My request group by type, and count:</p>
  
  <pre class="lang-js prettyprint-override"><code>[{
      $group : {
          _id : {
              type : '$type'
          },
          "count" : {
              "$sum" : 1
          }
      }
  }]
  </code></pre>
  
  <p>Result:</p>
  
  <pre class="lang-js prettyprint-override"><code>[
      {
          _id {
              type : 'big',
          },
          count : 2
      },
      {
          _id {
              type : 'short',
          },
          count : 3
      }
  ]
  </code></pre>
  
  <p>But I'd like to have count AND percentage, like that:</p>
  
  <pre class="lang-js prettyprint-override"><code>[
      {
          _id {
              type : 'big',
          },
          count: 2,
          percentage: 40%
      },
      {
          _id {
              type : 'short',
          },
          count: 3,
          percentage: 60%
      }
  ]
  </code></pre>
  
  <p>But I've no idea how to do that. I've tried <code>$divide</code> and other things, but without success. Could you please help me?</p>