 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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"       ]    ] }Advertisements
 