Chapter3 - Aggregation: $project vs $group

Hi all,

I’m working on the $max, $min, $avg on the db.Movies …
following the examples on the videos 1 & 2 we get one line result from the statement…
when I run my statement, if I use:
$project - result is a list
$group - 1 line result (as expected)

and I’m not changing nothing in the query.
could someone explain me why the query from the course:
" db.icecream_data.aggregate([
{ “$project”: { “_id”: 0, “max_high”: { “$max”: “$trends.avg_high_tmp” } } }
]) "
returns only one line?

Thank you,

That query includes a $max calculation. The $max aggregation pipeline operator looks at all docs in the pipeline, then returns only the doc containing the highest value for the specified field. The “one line” you see returned is the single doc containing the highest value.

The docs say that, just not in a very friendly way.

When used in the $group stage, $max returns the maximum value that results from applying an expression to each document in a group of documents

So, the group does a $max on the $max of the documents…
OK, thank you!


But why does the icecream query only return one line? I don’t understand how it’s doing something different than the movies query.

The way it’s written, I understand why the icecream query returns the maximum of the documents. But how is doing $project different using the movie query?