Chapter1 - Quiz Which of the following is/are true of the $match stage?

Hey guys

Why is this option :
$match can use both query operators and aggregation expressions.

is considered incorrect?

I mean $match here uses both
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.solarSystem.aggregate([{ $match: { type: {$ne: “Star”}} }]).pretty()

Any explanation?

@Mehdi_10232

The example you give uses a query operation – $type – as defined in the documentation here. In what way do you think this represents an aggregation expression?

I thougt when there is the key work aggregate with $match…it would be an aggregation expression

db.solarSystem.aggregate([{ $match: { type: {$ne: “Star”}} }]).pretty()

@Mehdi_10232 I believe that "when there is the key word .aggregate with $match " it would be known as an aggregation pipeline. Therefore I would read your example as an aggregation pipeline that $matches documents that have a $type that do not equal ‘Star’.

In the question from the quiz it talk about if $match can use query operators and aggregation expressions?

With regards to an aggregation expression I found this part of the documents, which list all the available aggregation expressions.

And Query operators here.

What you will find ( and I believe is what is causing that confusion :wink: ) is that some of the query operators are identical to the aggregation expression, in name and final result. Operators like $gt use a key value syntax -> {field: {$gt: value} } However with the aggregation expression ‘version’ of $gt the doc tell us that it takes an array of two values to compare. -> { $gt: [ <expression1>, <expression2> ] }

Therefore you can see that Query Operators are different than Aggregation Expressions even though some of the aggregation expressions function similar to, and have similar names as query operators. But there are numerous aggregation expressions compares to query operators.

And lastly you can in fact run aggregation expression with $match or .find() by using $expr: { <expression>} :

I see…
Thanks natac for clearing this confusion

I see…
Thanks natac for clearing this confusion

Thanks @Natac13

I have a question though. If I can in fact run aggregation expression with $match or .find() by using $expr, it means that $match can use aggregation expressions (indirectly) and query operators (directly), right?

I think the statement should be:

  • $match can use both query operators and aggregation expressions without using $expr operator.

or

  • $match can use both query operators and aggregation expressions directly

English is not my native language. Am i making any sense?
If the original statement is complete and without any possibility of ambiguity, what am I missing?

Hi @Camilo_24839,

You are right! The quiz options can be re-framed to ensure clarity and remove the ambiguity.

I will share this feedback with the team. As we are working on revamping the MongoDB Aggregation course, we will ensure that all user feedback is captured in the new course version.

Please feel free to reach out if you have any additional questions.

Kind Regards,
Sonali Mamgain