$not (Logical NOT)

Last updated: 2026-10-09

$not (Logical NOT)

$not negates an operator expression, returning documents that fail the inner condition. `{ price: { $not: { $gt: 50 } } }` matches products priced at most 50. $not does not match documents missing the field, and it requires an operator expression inside — not a regex literal.

CategoryLogical
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ <field>: { $not: { <operator expression> } } }

⚙️ Parameters

fieldThe document field to match.
operator expressionThe operator condition to negate, e.g. { $gt: 50 }.

Returns:Cursor of matching documents

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// $not: price not greater than 50
db.products.find({ price: { $not: { $gt: 50 } } })

// Equivalent: $lte is more direct
db.products.find({ price: { $lte: 50 } })

Output:

// Returns products priced at most 50; missing-field documents are excluded

📌 Notes

📚 Related Tutorials

❓ FAQ

QWhat is the difference between $not and $ne?
A$ne means not-equal-to-a-value; $not negates a whole operator expression, e.g. { $not: { $gt: 50 } }.
QDoes $not match documents where the field is missing?
ANo. A missing field fails the inner condition, so the negation still does not match.
QCan $not negate a regex?
AYes, via { $not: { $regex: '...' } }, but not as { $not: /pattern/ }.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏