
- 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
Fetch a specific document in MongoDB with array elements
To fetch a specific document, use dot notation in MongoDB find(). Let us create a collection with documents −
> db.demo672.insertOne({Brand:[{CategoryName:"Mobile","Name":"Oppo"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3ea9b04263e90dac943e5") } > db.demo672.insertOne({Brand:[{CategoryName:"Mobile","Name":"Samsung"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3eaa404263e90dac943e6") } > db.demo672.insertOne({Brand:[{CategoryName:"Mobile","Name":"OnePlus"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea3eacc04263e90dac943e7") }
Display all documents from a collection with the help of find() method −
> db.demo672.find();
This will produce the following output −
{ "_id" : ObjectId("5ea3ea9b04263e90dac943e5"), "Brand" : [ { "CategoryName" : "Mobile", "Name" : "Oppo" } ] } { "_id" : ObjectId("5ea3eaa404263e90dac943e6"), "Brand" : [ { "CategoryName" : "Mobile", "Name" : "Samsung" } ] } { "_id" : ObjectId("5ea3eacc04263e90dac943e7"), "Brand" : [ { "CategoryName" : "Mobile", "Name" : "OnePlus" } ] }
Following is the query to fetch a specific document −
> db.demo672.find({"Brand.Name":"OnePlus"});
This will produce the following output −
{ "_id" : ObjectId("5ea3eacc04263e90dac943e7"), "Brand" : [ { "CategoryName" : "Mobile", "Name" : "OnePlus" } ] }
- Related Articles
- Accessing array values in a MongoDB collection to fetch a specific document
- Make nested queries in MongoDB 4 to fetch a specific document
- How to find specific array elements in MongoDB document with query and filter with range?
- Find document with array that contains a specific value in MongoDB
- Update a specific MongoDB document in array with $set and positional $ operator?
- MongoDB query to fetch a specific document rom documents with field value set using NumberInt()?
- Query an array in MongoDB to fetch a specific value
- Extract a MongoDB document with a specific string
- MongoDB query to implement nor query to fetch documents except a specific document
- Find MongoDB document with array containing the maximum occurrence of a specific value
- MongoDB query to remove array elements from a document?
- How to project specific elements in an array field with MongoDB?
- Fetch specific field values in MongoDB
- Fetch specific multiple documents in MongoDB
- How to get a specific object from array of objects inside specific MongoDB document?

Advertisements