Lab $unwind - I can't see where I'm wrong


I’ve a pipeline that provide output that look to me similar and the same format to the lab request - and it fail :disappointed: : will someone light my eyes? thanks!

this is mine:
{ “_id” : “John Wayne”, “numFilms” : 107, “average” : 6.4 }
this is the labs:
{ “_id”: “First Last”, “numFilms”: 1, “average”: 1.1 }

I clicked on the “SEE DETAILED ANSWER” link on the top red line and copy the code from there and it produced the same output like mine: { “_id” : “John Wayne”, “numFilms” : 107, “average” : 6.4 }
so now I really don’t understand - HELP I NEED SOMEBODY


Do you mean the format is correct but you can’t see how the pipeline isn’t? Then include the pipeline.

Otherwise, what is the question?

Hi Santiago,

thanks for replying, here is my code:

var pipeline = [
{ $unwind : "$cast" },
{ $group: { 
    "_id" : "$cast", 
	"numFilms" : { $sum : 1 },
	"average" : { $avg : "$imdb.rating" }
{ $sort : { "numFilms" : -1 } },
{ $limit : 1 },
{ $project: { _id:1, numFilms: 1, average: { $trunc: [ "$average", 1 ] } }},


and this is the code output:

{ "_id" : "John Wayne", "numFilms" : 107, "average" : 6.4 }

this is the Lab demand:

{ "_id": "First Last", "numFilms": 1, "average": 1.1 }

so I don’t understand where is my wrong?

by the way, this is the output when sort order is 1:

{ "_id" : "Noelle Middleton", "numFilms" : 1, "average" : 5.2 }

As far as I remember, this exercise requires all 5 actors have been part of the film. Can you double check this?

If this is the case, take a look at setIntersection on the docs.

The lab demand is not to produce this exact answer. It is written:

Provide the input output in the following order and format.

I have embolden the important words. Order and format. Your John Wayne output seems to have the correct order and correct format but you write that your answer is marked as wrong. The only difference I see is the spaces you have in front of your colons. Can you post a screen show with your answer in the answer box with the validator indicating the invalid answer?

Hi steevej-1495,

here the print screen:

and the same code on my terminal:

thank you.

Hi Santiago,

thanks for replying, here is the exercise requirement:

Chapter 3: Core Aggregation - Combining Information

Lab - $unwind


Let's use our increasing knowledge of the Aggregation Framework to explore our movies collection in more detail. We'd like to calculate how many movies every **cast** member has been in and get an average imdb.rating for each cast member.

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?

Provide the input in the following order and format

{ "_id": "First Last", "numFilms": 1, "average": 1.1 }

we use the $setIntersection at the first [optional lab] & second [Lab 2.1] chapters
thank you.

I see. The question started with

What is the name, number of movies, and average rating (truncated to one decimal) for the …

and ended with

Provide the input output in the following order and format .

So they wanted the name, number of movies and average rating, so they wanted the output but they wrote input. That’s where you got mixed up. I will flag this post at it is a real issue. Thanks for persisting.

Hi Sonali Mamgain,

I see that you are the “MongoDB Staff-Curriculum Services Engineer”, will you please fix this issue, and fix my lab grade?

Thank you.

Provide the input (to the Lab UI, as the answer) in the following order and format:

There’s a lot of ambiguity in small things all through this complex course. I admit I had to re-read the instructions on this one a couple of times, and play with my code to get the correct format.


Because you entered the pipeline in the answer box rather than the answer. Your confusion comes from


now I got you - thanks.