$in

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

Reference group: Conditional and logical expressions

What it does

Aggregation $in checks whether a value is in an array.

Syntax

{$in: [value, array]}

Use case

Evaluate membership in computed lists.

Important notes

Different syntax from query predicate $in.

$in: practical example
{ $project: { allowed: { $in: ["$role", ["admin", "editor"]] } } }
💡 Explanation Aggregation $in checks whether a value is in an array. When to use it Evaluate membership in computed lists. Caution Different syntax from query predicate $in.
Key Takeaways
  • Aggregation $in checks whether a value is in an array.
  • Typical use: Evaluate membership in computed lists.