$setDifference

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

Reference group: Array aggregation expressions

What it does

Returns values in the first array but not the second.

Syntax

{$setDifference: [array1, array2]}

Use case

Find unmet requirements.

$setDifference: practical example
{ $project: { missing: { $setDifference: ["$requiredSkills", "$skills"] } } }
💡 Explanation Returns values in the first array but not the second. When to use it Find unmet requirements.
Key Takeaways
  • Returns values in the first array but not the second.
  • Typical use: Find unmet requirements.