Logical Operators

noun

say it: “LOJ-ih-kul OP-uh-ray-terz” /ˈlɑdʒɪkəl ˈɑpəreɪtərz/

Words that join or flip true-or-false conditions, such as and, or and not; in a MongoDB filter they start with a dollar sign, such as $or.

What are logical operators in a MongoDB filter?

Logical operators combine conditions in a filter: $or matches when any condition is true, $and when all are, $nor when none is, and $not flips one condition. $or, $and and $nor take a list of conditions.

db.recipes.find({ $or: [{ cuisine: "Thai" }, { minutes: { $lt: 15 } }] });
// every Thai recipe, plus any recipe under 15 minutes

In a sentence

  • “A filter with two fields is already an and, so the logical operators matter most for or.”
  • “Logical operators let the filter ask for recipes that are vegetarian or quick, not only both.”

Level: Apprentice · More MongoDB terms at this level

Updated

In other subjects