
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Querying an array of arrays in MongoDB?
Use $in operator to query an array of arrays in MongoDB. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −
> db.arrayOfArraysDemo.insertOne({"EmployeeName":"Larry","EmployeeSkills":[["Java","MongoDB","MySQL","SQL Server"]]}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f7a8d8d10a061296a3c5b") } > db.arrayOfArraysDemo.insertOne({"EmployeeName":"Mike","EmployeeSkills":[["C","C++"]]}); { "acknowledged" : true, "insertedId" : ObjectId("5c7f7aa68d10a061296a3c5c") }
Display all documents from a collection with the help of find() method. The query is as follows −
> db.arrayOfArraysDemo.find().pretty();
The following is the output −
{ "_id" : ObjectId("5c7f7a8d8d10a061296a3c5b"), "EmployeeName" : "Larry", "EmployeeSkills" : [ [ "Java", "MongoDB", "MySQL", "SQL Server" ] ] } { "_id" : ObjectId("5c7f7aa68d10a061296a3c5c"), "EmployeeName" : "Mike", "EmployeeSkills" : [ [ "C", "C++" ] ] }
Here is the query for querying an array of arrays in MongoDB −
> db.arrayOfArraysDemo.find({'EmployeeSkills':{$elemMatch:{$elemMatch:{$in:['MongoDB']}}} }).pretty();
The following is the output −
{ "_id" : ObjectId("5c7f7a8d8d10a061296a3c5b"), "EmployeeName" : "Larry", "EmployeeSkills" : [ [ "Java", "MongoDB", "MySQL", "SQL Server" ] ] }
- Related Articles
- Querying from part of object in an array with MongoDB
- Querying internal array size in MongoDB?
- Querying array elements with MongoDB?
- Make an array of multiple arrays in MongoDB?
- Querying on an array of objects for specific nested documents with MongoDB?
- How to use arrays as filters by querying subdocuments in MongoDB?
- Querying array of Embedded Documents in MongoDB based on Range?
- Querying object's field array values in MongoDB?
- Native Querying MongoDB inside array and get the count
- Querying null value in MongoDB?
- Querying with MongoDB subelement?
- How to improve querying field in MongoDB?
- Fetch records in MongoDB on querying its subset
- Get the smallest array from an array of arrays in JavaScript
- Search an array of hashes in MongoDB?

Advertisements