$pull
Reference group: Array update operators
What it does
Removes all array elements matching a value or condition.
Syntax
{$pull: { array: condition }}
Use case
Remove revoked roles.
$pull: practical example
db.users.updateOne({ _id: userId }, { $pull: { roles: "temporary" } })💡 Explanation
Removes all array elements matching a value or condition.
When to use it
Remove revoked roles.
Key Takeaways
- Removes all array elements matching a value or condition.
- Typical use: Remove revoked roles.