MongoDB NOR Operator ( $nor ) (original) (raw)

Last Updated : 5 May, 2026

The noroperatorreturnsdocumentswherenoneofthegivenconditionsmatch,it′sthelogicalinverseofnor operator returns documents where none of the given conditions match, it's the logical inverse of noroperatorreturnsdocumentswherenoneofthegivenconditionsmatch,itsthelogicalinverseofor, useful for excluding multiple criteria in one query.

Syntax

{ $nor: [ { Expression1 }, { Expression2 }, ... { ExpressionN } ] }

Examples of using MongoDB Operations

In the following examples, we are working with:

Screenshot-2026-02-10-102052

Example 1: Matching Values using $nor Operator

Retrieve documents that do not match any of the specified conditions, meaning documents where the salary is not 3000 and the branch is not "ECE".

**Query:

db.contributor.find({$nor: [{salary: 3000}, {branch: "ECE"}]})

**Output:

Screenshot-2026-02-10-102418

Example 2: Matching Values in Nested/Embedded Documents using $nor Operator

Retrieve contributor documents where the age is not 24 and the state is not "California, USA" in the personal subdocument.

**Query:

db.contributor.find({$nor: [{ "personal.age": 24 }, { "personal.state": "California, USA" }]})

**Output:

Screenshot-2026-02-10-103134

Example 3: Matching Values in an Array using $nor Operator

Retrieve documents where the language field does not contain either "Java" or "C++".

**Query:

db.contributor.find({$nor: [{language: {$in: ["Java", "C++"]}}]})

**Output:

Screenshot-2026-02-10-103453

Usage of $nor Operator in MongoDB

The $nor operator in MongoDB helps exclude documents by ensuring none of multiple conditions match. It’s ideal for applying a logical NOT across combined criteria in complex filters.

Advantages of Using $nor in MongoDB

The $nor operator enables flexible exclusion in MongoDB queries by returning documents where none of multiple conditions match.