Skip to main content

$contains

The $contains operator checks if the first string contains the second string as a substring.

Input

  • An array containing exactly two string values: the main string and the substring to search for

Output

  • true if the first string contains the second string as a substring
  • false otherwise

Examples

Contains Substring

{
  "$contains": [
    "Hello, world!",
    "world"
  ]
}
Result: true

Does Not Contain

{
  "$contains": [
    "Hello, world!",
    "universe"
  ]
}
Result: false

Field Value

{
  "$contains": [
    {
      "$input": "description"
    },
    "urgent"
  ]
}
Result: true if the description field contains the word “urgent”, otherwise false