$size

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

Reference group: Array query operators

What it does

Matches arrays with exactly n elements.

Syntax

{ arrayField: { $size: n } }

Use case

Find arrays of exact length.

Important notes

Query $size does not directly support arbitrary ranges.

$size: practical example
db.posts.find({ tags: { $size: 3 } })
💡 Explanation Matches arrays with exactly n elements. When to use it Find arrays of exact length. Caution Query $size does not directly support arbitrary ranges.
Key Takeaways
  • Matches arrays with exactly n elements.
  • Typical use: Find arrays of exact length.