Skip to main content

$and

The $and operator evaluates multiple expressions and returns true if all of them are truthy, otherwise it returns false.

Input

  • An array of expressions to evaluate
  • Each expression is evaluated in order from left to right

Output

  • true if all expressions evaluate to truthy values
  • false if any expression evaluates to a falsy value

Examples

Basic Example

{
  "$and": [
    true,
    true
  ]
}
Result: true

Multiple Expressions

[
  {
    "$and": [
      {
        "$gte": [
          {
            "$input": "age"
          },
          18
        ]
      },
      {
        "$eq": [
          {
            "$input": "status"
          },
          "active"
        ]
      }
    ]
  }
]
Result: true if the age is greater than or equal to 18 and the status is “active”, otherwise false

With Falsy Value

{
  "$and": [
    true,
    false,
    true
  ]
}
Result: false