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
$mustor a field condition:$mustNotfilters the matching documents. It removes the documents that match its conditions. - On its own: the query matches every document that
$mustNotdoes not exclude. All of these documents have a score of0. - Inside
$should:$mustNotis one of the alternatives. It matches every document it does not exclude, with a score of0.
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: