title: MongoDB Spring Data how can I aggregate count from multiple fields?
body: <p>Let's assume that there are some data like this:</p>
  
  <pre><code>{
  "orderId": 1,
      "manager" : [ 
          {
              "userId" : "UserId1"
          }
      ],
      "employee" : [ 
          {
              "userId" : "UserId3"
          }
      ]
  }
  
  {
  "orderId": 2,
      "manager" : [ 
          {
              "userId" : "UserId1"
          }
      ],
      "employee" : [ 
          {
              "userId" : "UserId2"
          }
      ]
  }
  
  {
  "orderId": 3,
      "manager" : [ 
          {
              "userId" : "UserId1"
          }
      ],
      "employee" : [ 
          {
              "userId" : "UserId2"
          }
      ]
  }
  </code></pre>
  
  <p>The result should be:</p>
  
  <pre><code>{  
     "Agg":[  
        {  
           "userId":"UserId1",
           "total":3
        },
        {  
           "userId":"UserId2",
           "total":2
        },
        {  
           "userId":"UserId3",
           "total":1
        }
     ]
  }
  </code></pre>
  
  <p>I want to get all aggregated count of userId engaged in some process. I need to group by userId from "employee" and "manager" objects and sum them. Only what I can dois group by userId from one list:</p>
  
  <pre><code>Aggregation agg = newAggregation(
     match(Criteria.where("project").is("project")),
     unwind("manager"),
     group("manager.userId").count().as("total"),
     project("total").and("userId").previousOperation(),
     sort(Sort.Direction.DESC, "total")
  );
  </code></pre>
  
  <p>How can I aggregate count from "manager" and "employee" fields?</p>