
- 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
MongoDB multidimensional array projection?
For MongoDB multidimensional array projection, you need to use aggregate framework. Let us first create a collection with documents. Here, we have multidimensional array for Student marks −
> db.multiDimensionalArrayProjection.insertOne( ... { ... "StudentFirstName" : "Chris", ... "StudentMarks" : [ [98, 99],[56,79] ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cc6b75a9cb58ca2b005e66c") }
Following is the query to display all documents from a collection with the help of find() method −
> db.multiDimensionalArrayProjection.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5cc6b75a9cb58ca2b005e66c"), "StudentFirstName" : "Chris", "StudentMarks" : [ [ 98, 99 ], [ 56, 79 ] ] }
Following is the query for MongoDB multidimensional array projection −
> db.multiDimensionalArrayProjection.aggregate([ ... { $unwind: '$StudentMarks' }, ... { $limit: 1 }, ... { $project: { _id: 0, StudentMarks: 1 } }, ... { $unwind: '$StudentMarks' }, ... { $skip: 1 }, ... { $limit: 1 } ... ]);
This will produce the following output −
{ "StudentMarks" : 99 }
- Related Articles
- MongoDB projection result as an array of selected items?
- MongoDB aggregation and projection?
- Projection result as an array of selected items in MongoDB?
- Projection of arrays to get the first array element from MongoDB documents
- Projection of one column in MongoDB?
- MongoDB projection on specific nested properties?
- PHP Multidimensional Array.
- MongoDB Limit fields and slice projection together?
- Multidimensional array in Java
- Single dimensional array vs multidimensional array in JavaScript.
- How to convert Multidimensional PHP array to JavaScript array?
- What is a Multidimensional array in Java?
- Get array upperbound in Java Multidimensional Arrays
- Initialization of a multidimensional array in C
- Sort multidimensional array by multiple keys in PHP

Advertisements