Skip to main content

What does $not do?

$not is a logical negation operator. It inverts a condition, making it the opposite.

Example:

js
db.users.find({ age: { $not: { $gt: 18 } } })

The query returns documents where age is not greater than 18 (that is, 18 or less).

The key idea: $not is applied on top of another operator ($gt, $lt, $regex, etc.) and flips its condition.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.