Chapter 0: Difference between operators and expressions

I get that expressions are like functions. But on the video, $gte used as {$gte: -40} is an operator while $gt used as {$gt: [’$numberOfMoons’, 0]} is an expression. Can someone elaborate on this?

Simple queries like used in the find() method or $match stage are of the form:

field_name : value 
field_name : { operator : value }

More complex queries, like when you want to compare 2 fields withing the same document are with an $expr:{ complex_query } sub-document.

When ever you <expression> in the documentation you should use the extended syntax of $expr (without the $expr because it is implicit) and when you see <query>, use the simple syntax.


so it depends on how we use the operators. If we use $gt: value, $gt is an operator whereas in $gt: $gt is an expression. Am I right?

yes but the how is determine by the where you use $gt.

1 Like

Thanks for the help :smile:

1 Like