Chapter 3 - $project

At the start of this chapter is the following statement about 18 seconds in.

_Accumulator expressions in $project operate over an array in the current document, they do not carry over values over all documents.

They do not carry values over to each document encountered_

I understand the commands, but I don’t understand why this statement has been made.

Is it saying that any accumulator expressions used in $project, cannot carry their values over multiple documents, so I cannot average the movie critic value over every document. I can average values in that document only.

If that is the case, we would perform this average function via a $group?

OR is it saying that accumulator expressions only work on arrays in $project.

PS - If this is the case, then it is always good that the course, gives the other side of the example, it is easier to compare and contrast examples.

PPS - There do seem to be a lot of expressions, that work one way in $project, subtly different in $group , little gotchas you need to be aware of.

Please revisit Chapter 0 - Lecture: The Concept of Pipelines.

In there you will see the basics of $match, $project and $group. To resume:

$match takes n documents from its preceding stage and passes m < n documents to the next stage without altering any documents.
$project takes n documents from its preceding stage and passes n modified documents. So $project works internally within each document it processes.
$group takes n documents from its preceding stage and passes m < n documents. Each output document represents a group having _id as the group id. Accumulators operates on all documents within the group.

Thanks, I thought I had missed something, or some greater concept was being explained.

Basically the whole line was a simple “The following commands only work on this on a specific document”.

I am like that too.

When I find that things are simple I always wondering if I missed something.

I wasted an hour + on that, try to work out the deeper meaning. I am sure I could have explained it quicker, with the example on the page.

Off to make a cup of tea.

PS - Thanks btw.