Lab: $group and Accumulators

I am not clearly understanding what we have to use for grouping the documents before applying the accumulators like $max, $min, $avg, $stdDevPop.
[In the last lab, we calculated a normalized rating that required us to know what the minimum and maximum values for imdb.votes were. These values were found using the $group stage!]

Take a look at the following:

https://s3.amazonaws.com/edu-downloads.10gen.com/M121_2018_November/static/handouts/m121/group_stage.js

That was part of the handout and there is many example of $group.

After filtering the resultset for ‘Won Oscar’ films, document count is 1262, and then I am grouping on id as null and applying the accumulators. I am also using “$stdDevSamp” for deviation but o/p is not matching with one of the option, would you mind validating the filtered document count ?

I am not sure if this is the number you want but I am getting 914 movies that won at least 1 oscar. I don’t want to write the pipeline I used to get that number since it gives part of the answer to the lab. However I can say that the first stage was a $match with $regex on the award field so that only movies with Won Oscar are passed to the second stage. And the second stage was simply a $group using $sum : 1.

Correct, I am also getting 914 as count. I am using computation field from previous lab in the project stage after $match, and then $group and then accumulator of $min within group for lowest_rating. I am not finding 2.75 in any of the options ?

lowest_rating: {$min: “$normalized_rating”}
_id:null
count:914
lowest_rating:2.751346065347446

They are not interested with the normalized rating of the previous lab. It is simpler. The problem is stated as

calculate the standard deviation, highest, lowest, and average ‘imdb.rating’
1 Like

Hi I am stuck with this lab, my answer is not any of the options. Also it appears none of the options can be correct. The collection includes this document { “_id” : ObjectId(“573a13dff29313caabdb814a”), “title” : “Gunday”, “awards” : “1 win & 3 nominations.”, “imdb” : { “rating” : 1.9, “votes” : 53044, “id” : 2574698 } }.

Which has min rating 1.9, and has won an oscar however there are no min options where the rating is 1.9.

Any help much appreciated

1 Like

The lab description provides the following hint:

HINT - All movies in the collection that won an Oscar begin with a string resembling one of the following in their awards field

Won 13 Oscars
Won 1 Oscar

The value of the awards in the document you shared is 1 win & 3 nominations. which does not look at all like the supplied examples.

Revise your $match stage to make sure you select the appropriate documents.

1 Like

Thanks that fixed it, I should pay more attention.

1 Like