
- 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 query to fetch a specific document rom documents with field value set using NumberInt()?
The NumberInt() is used to explicitly specify 32-bit integers. Let us create a collection with documents −
> db.demo357.insertOne( ... { ... "FirstName" : "Chris", ... "Age" : 21, ... "details" : { ... "studentDetails" : { ... "id" : NumberInt(101) ... } ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e568fa6f8647eb59e5620c9") } > db.demo357.insertOne( ... { ... "FirstName" : "David", ... "Age" : 23, ... "details" : { ... "studentDetails" : { ... "id" : NumberInt(110) ... } ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e568fbaf8647eb59e5620ca") }
Display all documents from a collection with the help of find() method −
> db.demo357.find();
This will produce the following output −
{ "_id" : ObjectId("5e568fa6f8647eb59e5620c9"), "FirstName" : "Chris", "Age" : 21, "details" : { "studentDetails" : { id" : 101 } } } { "_id" : ObjectId("5e568fbaf8647eb59e5620ca"), "FirstName" : "David", "Age" : 23, "details" : { "studentDetails" : { "id" : 110 } } }
Here is the query to get specific document −
> db.demo357.find({"details.studentDetails.id":NumberInt(110)});
This will produce the following output −
{ "_id" : ObjectId("5e568fbaf8647eb59e5620ca"), "FirstName" : "David", "Age" : 23, "details" : { "studentDetails" : { "id" : 110 } } }
- Related Articles
- MongoDB aggregation to fetch documents with specific field value?
- MongoDB query to implement nor query to fetch documents except a specific document
- Match MongoDB documents with field value greater than a specific number and fetch them?
- MongoDB query to fetch a document that does not have a particular field?
- MongoDB query to pull a specific value from a document
- Fetch a specific document in MongoDB with array elements
- Query an array in MongoDB to fetch a specific value
- MongoDB query to match documents with array values greater than a specific value
- Find the document by field name with a specific value in MongoDB?
- Find documents with arrays not containing a document with a particular field value in MongoDB?
- Fetch specific multiple documents in MongoDB
- MongoDB query to remove a specific document
- MongoDB query to add up the values of a specific field in documents
- MongoDB query (aggregation framework) to match a specific field value
- Fetch multiple documents in MongoDB query with OR condition?

Advertisements