Overview of Filter Operator $not

Query-by-example filter operator $not negates the behavior of its operand, which is a JSON object containing one or more comparison clauses, which are implicitly ANDed.

When any of those clauses evaluates to false, the application of $not to them evaluates to true. When all of them evaluate to true, it evaluates to false.

For example, this filter matches Example 2-1 and Example 2-3: document 1 has a field matching path address.zip and whose value is not "90001", and document 3 has no field matching path address.zip.

{"address.zip" : {"$not" : {"$eq" : "90001"}}}

The $not operand in the following filter has two comparison clauses. It too matches Example 2-1 and Example 2-3, because each of them has an age field whose value is not both greater than 46 and less than 65.

{"age" : {"$not" : {"$gt" : 46, "$lt" : 65}}}

Related Topics