title: How to make pymongo aggregation with count all elements and grouping by one request
body: <p>I have a collection with fields like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>{
      "_id":"5cf54857bbc85fd0ff5640ba",
      "book_id":"5cf172220fb516f706d00591",
      "tags":{
          "person":[
              {"start_match":209, "length_match":6, "word":"kimmel"}
          ],
          "organization":[
              {"start_match":107, "length_match":12, "word":"philadelphia"},
              {"start_match":209, "length_match":13, "word":"kimmel center"}
          ],
          "location":[
              {"start_match":107, "length_match":12, "word":"philadelphia"}
          ]
      },
      "deleted":false
  }
  </code></pre>
  
  <p>I want to collect the different words in the categories and count it.
  So, the output should be like this:</p>
  
  <pre><code>{
      "response": [
          {
              "tag": "location",
              "tag_list": [
                  {
                      "count": 31,
                      "phrase": "philadelphia"
                  },
                  {
                      "count": 15,
                      "phrase": "usa"
                  }
               ]
          },
          {
              "tag": "organization",
              "tag_list": [ ... ]
          },
          {
              "tag": "person",
              "tag_list": [ ... ]
          },
      ]
  }
  </code></pre>
  
  <p>The pipeline like this works:</p>
  
  <pre class="lang-py prettyprint-override"><code>def pipeline_func(tag):
      return [
          {'$replaceRoot': {'newRoot': '$tags'}},
          {'$unwind': '${}'.format(tag)},
          {'$group': {'_id': '${}.word'.format(tag), 'count': {'$sum': 1}}},
          {'$project': {'phrase': '$_id', 'count': 1, '_id': 0}},
          {'$sort': {'count': -1}}
      ]
  </code></pre>
  
  <p>But it make a request for each tag. I want to know how to make it in one request.
  Thank you for attention.</p>