
- 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
Finding documents in MongoDB collection where a field is equal to given integer value?
To find documents where a field is equal to given integer, use find(). Let us create a collection with documents −
> db.demo472.insertOne({"Project_Id":-101,"ProjectName":"Online Customer Tracking"});{ "acknowledged" : true, "insertedId" : ObjectId("5e80586cb0f3fa88e227907a") } > db.demo472.insertOne({"Project_Id":101,"ProjectName":"Online Banking System"});{ "acknowledged" : true, "insertedId" : ObjectId("5e805884b0f3fa88e227907b") } > db.demo472.insertOne({"Project_Id":102,"ProjectName":"Online Library System"});{ "acknowledged" : true, "insertedId" : ObjectId("5e805893b0f3fa88e227907c") }
Display all documents from a collection with the help of find() method −
> db.demo472.find();
This will produce the following output −
{ "_id" : ObjectId("5e80586cb0f3fa88e227907a"), "Project_Id" : -101, "ProjectName" : "Online Customer Tracking" } { "_id" : ObjectId("5e805884b0f3fa88e227907b"), "Project_Id" : 101, "ProjectName" : "Online Banking System" } { "_id" : ObjectId("5e805893b0f3fa88e227907c"), "Project_Id" : 102, "ProjectName" : "Online Library System" }
Following is the query to find documents in MongoDB collection where a field is equal to given integer value −
> db.getCollection('demo472').find({"Project_Id":-101});
This will produce the following output −
{ "_id" : ObjectId("5e80586cb0f3fa88e227907a"), "Project_Id" : -101, "ProjectName" : "Online Customer Tracking" }
- Related Articles
- How to add a new field to all the documents in a MongoDB collection
- Find all duplicate documents in a MongoDB collection by a key field?
- MongoDB query to update each field of documents in collection with a formula?
- Display only a single field from all the documents in a MongoDB collection
- MongoDB, finding all documents where property id equals to record id?
- Find a value in lowercase from a MongoDB collection with documents
- MongoDB query to get specific list of names from documents where the value of a field is an array
- Finding highest value from sub-arrays in MongoDB documents?
- MongoDB aggregation to fetch documents with specific field value?
- MongoDB query to find “where” Billing Address is Equal to Delivery Address from documents?
- Select MongoDB documents where a field either does not exist, is null, or is false?
- How to delete documents from a collection in MongoDB?
- How to retrieve documents from a collection in MongoDB?
- How to sum the value of a key across all documents in a MongoDB collection?
- MongoDB query to exclude if id is equal to a document field array value

Advertisements