
- 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
How to create double nested array in MongoDB?
To create a double nested array in MongoDB, let us implement the query to create a collection with documents. Within that, we have created a double nested array that displays Student Details, with the project name and technologies used to develop the same project:
> db.doubleNestedArrayDemo.insertOne( ... { ... "StudentId" : "1000", ... "StudentName" : "Larry", ... "StudentDetails" : [ ... { ... "ProjectName" : "Online Banking", ... "ProjectDetails" : [ ... { ... "TechnologyUsed" : "Java" ... }, ... { ... "TechnologyUsed" : "MySQL in Backend" ... } ... ] ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5c992bd7330fd0aa0d2fe4cc") } > db.doubleNestedArrayDemo.insertOne( { "StudentId" : "1001", "StudentName" : "Robert", "StudentDetails" : [ { "ProjectName" : "Student Web Tracker", "ProjectDetails" : [ { "TechnologyUsed" : "Django Framework" }, { "TechnologyUsed" : "MongoDB in Backend" } ] } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5c992cdb330fd0aa0d2fe4cd") }
Following is the query to display all the documents from a collection with the help of find() method
> db.doubleNestedArrayDemo.find().pretty()
This will produce the following output
{ "_id" : ObjectId("5c992bd7330fd0aa0d2fe4cc"), "StudentId" : "1000", "StudentName" : "Larry", "StudentDetails" : [ { "ProjectName" : "Online Banking", "ProjectDetails" : [ { "TechnologyUsed" : "Java" }, { "TechnologyUsed" : "MySQL in Backend" } ] } ] } { "_id" : ObjectId("5c992cdb330fd0aa0d2fe4cd"), "StudentId" : "1001", "StudentName" : "Robert", "StudentDetails" : [ { "ProjectName" : "Student Web Tracker", "ProjectDetails" : [ { "TechnologyUsed" : "Django Framework" }, { "TechnologyUsed" : "MongoDB in Backend" } ] } ] }
- Related Articles
- How to create a nested index in MongoDB?
- MongoDB $push in nested array?
- MongoDB query to aggregate nested array
- MongoDB query to sort nested array?
- How to add new item in nested array with MongoDB?
- Search for a text in MongoDBs Double Nested Array?
- Clearing items in a nested MongoDB array?
- MongoDB query to get array of nested string?
- MongoDB Increment value inside nested array?
- How to group nested fields in MongoDB aggregation with count value in array?
- Retrieve values from nested JSON array in MongoDB?
- Set filtering conditions for nested array in MongoDB
- Increment MongoDB value inside a nested array
- Query array of nested string with MongoDB?
- MongoDB query to get only specific fields in nested array documents?

Advertisements