Lab - $unwind - Core Aggregation - Combining Information

What is the name, number of movies, and average rating (truncated to one decimal) for the cast member that has been in the most number of movies with English as an available language?

I didnot fully understand the question.

For example

db.movies.aggregate([{$match: {cast: "Abhay Deol"}}, {$project: {_id: 0, cast: 1, "imdb.rating": 1, languages: 1}}]);

{ “cast” : [ “Abhay Deol”, “Ayesha Takia”, “Ayesha Jhulka”, “Apoorva Jha” ], “languages” : [ “Hindi”, “English” ], “imdb” : { “rating” : 7.7 } }
{ “cast” : [ “Abhay Deol”, “Satish Kaushik”, “Mohammed Faisal”, “Tannishtha Chatterjee” ], “languages” : [ “English”, “Rajasthani”, “Hindi” ], “imdb” : { “rating” : 6.9 } }
{ “cast” : [ “Abhay Deol”, “Paresh Rawal”, “Neetu Chandra”, “Archana Puran Singh” ], “languages” : [ “Hindi” ], “imdb” : { “rating” : 7.9 } }
{ “cast” : [ “Abhay Deol”, “Mahie Gill”, “Kalki Koechlin”, “Dibyendu Bhattacharya” ], “languages” : [ “Hindi”, “Panjabi”, “English”, “French”, “Tamil” ], “imdb” : { “rating” : 8.1 } }
{ “cast” : [ “Emraan Hashmi”, “Abhay Deol”, “Prasenjit Chatterjee”, “Kalki Koechlin” ], “languages” : [ “Hindi” ], “imdb” : { “rating” : 7.3 } }
{ “cast” : [ “Arjun Rampal”, “Abhay Deol”, “Manoj Bajpayee”, “Esha Gupta” ], “languages” : [ “Hindi” ], “imdb” : { “rating” : 6.9 } }

For this particular cast do I need to show
{ “_id”: “Abhay Deol”, “numFilms”: 6, “average”: 6 ratings avg}

or

{ “_id”: “Abhay Deol”, “numFilms”: 3, “average”: 3 ratings avg} // Considering only English

or

{ “_id”: “Abhay Deol”, “numFilms”: 6, “average”: 3 english ratings avg}

can you please suggest

Hi @Vivek_S,

For this lab, you need to find the cast member who has been in most number of English movies.

This is right. Here you are just checking for one actor but in the lab you need to check for all the cast members and find the one who did the maximum number of movies.

You can refer to the $unwind documentation for more details.

I would also recommend you to create the aggregation pipeline step-by-step and understand the output of each stage before adding the next stage.

Please feel free to reach out if you have any additional questions.

Kind Regards,
Sonali

1 Like

What is the name, number of movies, and average rating (truncated to one decimal) for the cast member that has been in the most number of movies with English as an available language?

I filtered languages = English and then calculated his number of movies

numFilms = Only English movies he acted and average is his english movies average rating.

Is this what expected?? or

numFilms= English + other movies, avg= English+ other movies

But I need to select one cast who acted in more number of english movies

castA – acted in 100 movies 90 English movies
castB-- acted in 110 movies 80 English movies

I will show castA because he acted in more english movies

But what about his numFilms and Avg?? is it overall movies count and overall movies avg rating? or only english movies count and average in the output?

Output also contains only one record right?

Hi @Vivek_S,

Your answer is correct. :white_check_mark:
I would recommend copy-pasting the answer directly from terminal to the Answer box.

Right, you need to first filter out the movies that contain “English” as a language. Then calculate the numFilms and average for those movies.

Note: I have edited your post to remove the lab answer as it can provide hints to other forum users.

Kind Regards,
Sonali

Many thanks… I was entering my pipeline queries into the answer box instead of result. So it failed twice. Many thanks for your help. Now it passed :slight_smile:

1 Like