
- 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
Multi-key Indexing on an entire array with MongoDB?
Let us first create a collection with documents −
> db.demo277.insertOne({"details":[{"FirstName":"John"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e48fb21dd099650a5401a52") } > db.demo277.insertOne({"details":[{"FirstName":"David"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e48fb27dd099650a5401a53") } > db.demo277.insertOne({"details":[{"FirstName":"Chris"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e48fb2bdd099650a5401a54") }
Display all documents from a collection with the help of find() method −
> db.demo277.find();
This will produce the following output −
{ "_id" : ObjectId("5e48fb21dd099650a5401a52"), "details" : [ { "FirstName" : "John" } ] } { "_id" : ObjectId("5e48fb27dd099650a5401a53"), "details" : [ { "FirstName" : "David" } ] } { "_id" : ObjectId("5e48fb2bdd099650a5401a54"), "details" : [ { "FirstName" : "Chris" } ] }
Following is the query to implement multi-key indexing on an entire array. It does scan full documents −
> db.demo277.find({"details":{FirstName:"David"}});
This will produce the following output −
{ "_id" : ObjectId("5e48fb27dd099650a5401a53"), "details" : [ { "FirstName" : "David" } ] }
- Related Articles
- Working with MongoDB $concatArrays in $project on existing multi-array field
- MongoDB query to remove entire array from collection?
- Query on the last object of an array with MongoDB
- Array index or indexing inner items in MongoDB to fetch values
- Update object in array with a specific key in MongoDB
- Implement $dateToString on array items with MongoDB
- Querying on an array of objects for specific nested documents with MongoDB?
- MongoDB multiple OR conditions on same key?
- Replace an array field value with MongoDB?
- Updating an array with $push in MongoDB
- How to delete an array element based on key in PHP?
- Changing the primary key on a MongoDB collection?
- Filter query on array of embedded document with MongoDB?
- Resolve ‘multi update only works with $ operators’ in MongoDb?
- Match multiple criteria inside an array with MongoDB?

Advertisements