$and (Logical AND)

Last updated: 2026-10-09

$and (Logical AND)

$and combines multiple query predicates; a document must satisfy all of them. `{ $and: [ { price: { $gt: 10 } }, { inStock: true } ] }`. Multiple fields in one query document already imply AND; $and makes the logic explicit and is required for several conditions on the same field.

CategoryLogical
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $and: [ { <condition1> }, { <condition2> }, ... ] }

⚙️ Parameters

conditions arrayAn array of query predicates; all of them must hold.

Returns:Cursor of matching documents

▶ Example

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

// $and: price above 10 and inStock true
db.products.find({
  $and: [
    { price: { $gt: 10 } },
    { inStock: true }
  ]
})

Output:

// Returns products satisfying both conditions (implicit AND gives the same result)

📌 Notes

📚 Related Tutorials

❓ FAQ

QWhat is the difference between $and and writing multiple fields?
AFunctionally equivalent; $and is for multiple conditions on one field or clearer logical structure.
QCan I write two $gt on the same field?
ADirectly it conflicts (keys are unique); use $and: { $and: [ { score: { $gt: 60 } }, { score: { $gt: 90 } } ] }.
QCan conditions inside $and nest $or?
AYes. Each element of $and can be any predicate, including $or and $nor.
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%

🙏 帮我们做得更好

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

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