I want to group them by name, and i want get the size of the document for both status pending and done . I able to get only pending one using { match: {status: "pending"}} .
The result will not be in the exact format you wish but close enough. May be $arrayToObject can do the final transformation. But I prefer to do this data cosmetic in the application rather than the data server.
Other than @steevej suggestion, you also might want to have a look at $facet to see if it satisfies your requirements. However I would suggest that you use the method that you’re more comfortable with and can maintain easily.