
- 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
Set multiple conditions in MongoDB and fetch value in a range
Let us create a collection with documents −
> db.demo59.insertOne({"Values":50}); { "acknowledged" : true, "insertedId" : ObjectId("5e286286cfb11e5c34d89923") } > db.demo59.insertOne({"Values":10}); { "acknowledged" : true, "insertedId" : ObjectId("5e286288cfb11e5c34d89924") } > db.demo59.insertOne({"Values":58}); { "acknowledged" : true, "insertedId" : ObjectId("5e28628ccfb11e5c34d89925") } > db.demo59.insertOne({"Values":78}); { "acknowledged" : true, "insertedId" : ObjectId("5e28628fcfb11e5c34d89926") }
Display all documents from a collection with the help of find() method −
> db.demo59.find();
This will produce the following output −
{ "_id" : ObjectId("5e286286cfb11e5c34d89923"), "Values" : 50 } { "_id" : ObjectId("5e286288cfb11e5c34d89924"), "Values" : 10 } { "_id" : ObjectId("5e28628ccfb11e5c34d89925"), "Values" : 58 } { "_id" : ObjectId("5e28628fcfb11e5c34d89926"), "Values" : 78 }
Here is the query to get value in a range −
> db.demo59.find({Values:{$gt:51, $lt:70}});
This will produce the following output −
{ "_id" : ObjectId("5e28628ccfb11e5c34d89925"), "Values" : 58 }
- Related Articles
- Implement multiple conditions in MongoDB?
- MongoDB query to get documents with multiple conditions set in $or?
- Fetch specific multiple documents in MongoDB
- MongoDB compound conditions to fetch documents?
- MongoDB query to fetch elements between a range excluding both the numbers used to set range?
- MongoDB query to find value in array with multiple criteria (range)
- MongoDB query to fetch date records (ISODate format) in a range
- Delete data from a collection in MongoDB using multiple conditions?
- Fetch multiple documents in MongoDB query with OR condition?
- How to update array with multiple conditions in MongoDB
- Set filtering conditions for nested array in MongoDB
- Set the value in local storage and fetch – JavaScript?
- Set MongoDB $slice with a range?
- MongoDB multiple OR conditions on same key?
- Query an array in MongoDB to fetch a specific value

Advertisements