Kørsel af følgende samlede pipeline skulle give dig det ønskede resultat:
db.collection.aggregate([
{
"$group": {
"_id": null,
"distinct_car_types": { "$addToSet": "$car_type" },
"distinct_colors": { "$addToSet": "$color" },
"distinct_num_doors": { "$addToSet": "$num_doors" }
}
},
{
"$project": {
"distinct_count_car_type": { "$size": "$distinct_car_types" },
"distinct_count_color": { "$size": "$distinct_colors" },
"distinct_count_num_doors": { "$size": "$distinct_num_doors" }
}
}
])