Chapter 4 - Lecture 1: $eq Operator

Hello,

Chapter 4 Lecture 1 mentions that when no logical operator is used in a find() expression, $eq is used implicitly.

I’m curious if there is preferred way to find by equality - or is it purely personal preference?

Hi @Sam_Hirst, welcome to the community :wave: .

$eq would be an advantage if you’re trying to craft a query programatically, as it will be simple to have a case selector where something is either $gt, $lt, or $eq, so instead of coding the equality as a special case, you can just interchange the three possibilities.

You can also take a look at this Jira ticket SERVER-1367 to understand its utility.

Thanks & Regards,
Sourabh Bagrecha,
MongoDB

1 Like