MongoDB: Challenges in $facet query in MongoDb

We have the brand and model information of the vehicle in the MongoDB collection.

We have written the query for the facet. We can able to get the unique brands with the count. But We need to get the unique models with a count of each brand in each brand object.

For ex:

We can able to get the brand count in facet. But we can’t able to get the model count in each brand. Any solutions for this?

$data =[ ‘brand’ => [ { ‘brand_1’ => [ brand_name => ‘Maruti’, brand_id =>1, count => 5 Models => [ { ‘model_name’ => ‘Swift’, ‘model_id’ => ‘1’, ‘count’ => 4, } ] }, { ‘brand_1’ => [ brand_name => ‘Maruti’, brand_id =>1, count => 5 Models => [ { ‘model_name’ => ‘Swift’, ‘model_id’ => ‘1’, ‘count’ => 4, } ] }] ] ]]

May be best to upload sample data and query to mongoplayground…

Do you want the count of distinct models per brand or the count of documents with that model and brand?