What if you could instantly find all items that match every detail you care about, without endless searching?
Why $all operator for matching all elements in MongoDB? - Purpose & Use Cases
Imagine you have a list of friends and their favorite fruits written on paper. You want to find friends who like both apples and bananas. You have to check each paper one by one, looking for both fruits.
Checking each paper manually is slow and easy to make mistakes. You might miss some friends who like both fruits or waste time rechecking the same papers.
The $all operator in MongoDB lets you quickly find documents where an array contains all specified elements. It does the hard work for you, so you get accurate results fast.
Check each document's array for 'apple' and 'banana' separately and combine results.
db.collection.find({ fruits: { $all: ['apple', 'banana'] } })You can instantly find records matching multiple criteria inside arrays without complex checks.
A music app wants to find playlists that include all your favorite genres like rock and jazz. Using $all, it quickly shows only those playlists.
Manually checking arrays is slow and error-prone.
$all matches documents containing all specified array elements.
This makes searching multi-element matches easy and reliable.