$$REMOVE
Reference group: Utility expressions and variables
What it does
Removes a field in supported projection/set contexts.
Syntax
$$REMOVE
Use case
Conditionally omit fields instead of outputting null.
$$REMOVE: practical example
{ $project: { optional: { $cond: [{ $eq: ["$include", true] }, "$value", "$$REMOVE"] } } }💡 Explanation
Removes a field in supported projection/set contexts.
When to use it
Conditionally omit fields instead of outputting null.
Key Takeaways
- Removes a field in supported projection/set contexts.
- Typical use: Conditionally omit fields instead of outputting null.