Visit complete MongoDB roadmap

← Back to Topics List


The $all operator is used to match arrays that contain all specified elements. This allows you to filter documents based on multiple values in a single array field.


The basic syntax for using the $all operator is:

  <field>: {
    $all: [<value1>, <value2>, ..., <valueN>]

Here, <field> refers to the name of the array field that should be queried, and <value1>, <value2>, ..., <valueN> are the values that you want to match against.


Let’s assume we have a collection movies with documents containing the following fields: _id, title, and tags. The tags field is an array of string values.

Here is an example document from the movies collection:

  _id: 1,
  title: "The Matrix",
  tags: ["action", "sci-fi", "cyberpunk"]

If you want to find all movies with the tags “action” and “sci-fi”, you can use the $all operator as shown below:

db.movies.find({ tags: { $all: ['action', 'sci-fi'] } });

This query would return all documents where the tags array contains both “action” and “sci-fi” values.


The $all operator allows you to match documents based on the presence of multiple values in an array field. It provides a simple and powerful way to query for documents that meet specific criteria within arrays.

Community is the 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Roadmaps Best Practices Guides Videos Store YouTube by Kamran Ahmed

Community created roadmaps, articles, resources and journeys to help you choose your path and grow in your career.

© · FAQs · Terms · Privacy


The leading DevOps resource for Kubernetes, cloud-native computing, and the latest in at-scale development, deployment, and management.