M121 Lab 1 - Basic Aggregation general questions

Hi, I have already successfully completed the lab, but I have a couple of questions that couldn’t understand reading the documentation:

  1. What is the difference between $project and $match, $project can be used to “filter”? Or is it just to pass certain values to the next stage?.

  2. I’ve seen aggregation pipelines with expressions and stages written between quotes ("$match", “$or”) and without ($match, $or). There is any difference, or anything I should be aware of?

Thank you very much!

1 Like

Hi

One
The main difference is that $match can’t alter the inner structure of a document. And the sole purpose of $project.

If the collection is a grid of documents (cells), match turns cells on and off. Project instead, changes the cells.

Indeed, this difference you will understand by practice, don’t worry too much.

Two
Normally you won’t have any trouble, because most drivers, where you type the queries, will fix that for you. But strictly speaking, JSON should be used, you can check the JSON rules here

Super clear, thanks!