$gte in Aggregation format versus Query format

Hello,

I am trying to understand something that has eluded me for a while. Why is the

db.movies.aggregate([{
$match: {$gte: ["$imdb.rating", 7 ]}
}]).itcount()

Not the correct format since it the stated format in the aggregation piple for $gte
$gte (aggregation) — MongoDB Manual

versus MQL query
db.movies.aggregate([{
$match: {$gte: [“imdb.rating”, 7 ]}
}]).itcount()

Thanks. I just find the mongodb syntax a little bit all over the place with it’s consistency.

Hi,

$match has been purposely left with the same syntax than find( ), hence $match does not follow aggregation syntax, but MQL syntax (unless you use $expr).

So, when using match, make yourself the idea that you’re writing find, and look up for MQL operators and not aggregation. For example $gte MQL.

2 Likes

Thank you for clarifying.

I am sure it was mentioned somewhere, but I probably wasn’t listening :slight_smile:

Thanks for the extra info on $expr, since I had noticed that in the Basics course when I redid that, but hadn’t bothered to ask the question.

I suppose I just like things to be consistent throughout, without having to learn exceptions.

1 Like