Comparison Operators
noun
say it: “kum-PAIR-ih-sun OP-uh-ray-terz” /kəmˈpɛrɪsən ˈɑpəreɪtərz/
Symbols or words that compare two values, such as greater than or not equal to; in a MongoDB filter they start with a dollar sign, such as $lt.
What are comparison operators in a MongoDB filter?
Comparison operators compare a field with a value inside a filter: $gt (greater than), $gte, $lt (less than), $lte, $ne (not equal), and $in and $nin for a list. Each goes in its own small document after the field's name.
db.recipes.find({ minutes: { $lt: 30 } }); // quicker than 30 minutes
db.recipes.find({ servings: { $gte: 4, $lte: 6 } }); // 4 to 6 servings
In a sentence
- “With the comparison operators $gte and $lte, the filter found recipes that serve 4 to 6 people.”
- “MongoDB's comparison operators go inside braces after the field: { minutes: { $lt: 30 } }.”
Level: Apprentice · More MongoDB terms at this level
Updated