I'm trying to count distinct values of multiple fields By one MongoDB Aggregation query.
So here's my data:
{
"car_type": "suv",
"color": "red",
"num_doors": 4
},
{
"car_type": "hatchback",
"color": "blue",
"num_doors": 4
},
{
"car_type": "wagon",
"color": "red",
"num_doors": 4
}
I want a distinct count of each field:
distinct_count_car_type=3
distinct_count_color=2
distinct_count_num_doors=1
I was able to group multiple fields and then do a distinct count but it could only give me a count on the first field. Not all of them. And also it's a large set of data.