Skip to main content

$ne

The $ne operator checks if two values are not equal.

Input

  • An array containing exactly two values to compare

Output

  • true if the two values are not equal
  • false if the two values are equal

Examples

Basic Inequality

{
  "$ne": [
    5,
    3
  ]
}
Result: true

Equality (Returns False)

{
  "$ne": [
    "hello",
    "hello"
  ]
}
Result: false

Comparing Field Values

{
  "$ne": [
    {
      "$input": "status"
    },
    "inactive"
  ]
}
Result: true if the status field is not “inactive”, otherwise false

Number Comparison

{
  "$ne": [
    {
      "$input": "count"
    },
    0
  ]
}
Result: true if the count field is not equal to 0, otherwise false