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?


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