$elemMatch

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Array query operators

What it does

Requires one array element to satisfy all inner conditions.

Syntax

{ array: { $elemMatch: { ... } } }

Use case

Match multiple predicates on the same embedded item.

$elemMatch: practical example
db.orders.find({ items: { $elemMatch: { sku: "KB-1", quantity: { $gte: 2 } } } })
💡 Explanation Requires one array element to satisfy all inner conditions. When to use it Match multiple predicates on the same embedded item.
Key Takeaways
  • Requires one array element to satisfy all inner conditions.
  • Typical use: Match multiple predicates on the same embedded item.