$all
noun
say it: “DOL-er AWL” /ˈdɑlər ˈɔl/
A MongoDB filter operator that matches an array containing every one of the given values.
What does $all do in a MongoDB filter?
$all matches documents whose array field holds every value in a list, in any order and with other items allowed. $in needs only one of them.
db.recipes.find({ tags: { $all: ["vegetarian", "quick"] } }, { _id: 0, name: 1 });
// [ { name: 'Greek Salad' } ] its tags: [ 'quick', 'summer', 'vegetarian' ]
In a sentence
- “$all found the recipes tagged both vegetarian and quick, whatever their other tags.”
- “Swapping $all for $in turned an and into an or, and the list grew.”
Level: Apprentice · More MongoDB terms at this level
Updated