JSON comparison operators
A number of different comparison operators are supported.
- equality comparison operator
- The following example uses the equality comparison operator:
{"name":"Joe"} - $ne (inequality comparator operator)
- The following example uses the inequality comparator operator:
{"age":{"$ne":3}} - $in
- The following example uses the $in operator to match at least
one value in a set:
You cannot use the $in operator, or the “in” operator in a index if the array contains different data types.{"age":{"$in":[1,2,3,4,5]}}Do not use different types for the same field, as shown in the following incorrect example:{"age":{"$in":[1,2,"A",3,4,5]}} - $nin
- The following example uses the $nin operator to match to no values
in a set, which is also referred to as the "not in" comparison operator:
{"age":{"$nin":[1,2,3,4]}} - $lt
- The following example uses the $lt operator, which is also referred
to as the "less than" comparison operator:
{"age":{"$lt":3}} - $lte
- The following example uses the $lte operator, which is also referred
to as the “less than or equals" operator:
{"age":{"$lte":3}} - $gt
- The following example uses the $gt operator, which is also referred
to as the “greater than" operator:
{"age":{"$gt":3}} - $gte
- The following example uses the $gte operator, which is also referred
to as the “greater than or equals" operator:
{"age":{"$gte":3}} - $regex (regular expression predicate)
- The following example uses the regular expression predicate ($regex):
{"name":{"$regex":/^a.*\/}}