$in
Reference group: Array query operators
What it does
Matches a value equal to any listed item; for arrays, a matching element is sufficient.
Syntax
{ field: { $in: [values] } }
Use case
Filter by allowed categories.
$in: practical example
db.products.find({ category: { $in: ["keyboard", "mouse"] } })💡 Explanation
Matches a value equal to any listed item; for arrays, a matching element is sufficient.
When to use it
Filter by allowed categories.
Key Takeaways
- Matches a value equal to any listed item; for arrays, a matching element is sufficient.
- Typical use: Filter by allowed categories.