Skip to main content

The $mustNot operator excludes documents that match any of the specified conditions.

How $mustNot works depends on the other conditions next to it:

  • With other conditions, such as $must or a field condition: $mustNot filters the matching documents. It removes the documents that match its conditions.
  • On its own: the query matches every document that $mustNot does not exclude. All of these documents have a score of 0.
  • Inside $should: $mustNot is one of the alternatives. It matches every document it does not exclude, with a score of 0.

Excluding Multiple Conditions#

When $mustNot contains multiple conditions (via array or object), documents matching ANY of those conditions are excluded. This is effectively an OR within the exclusion:

Examples#