- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find MongoDB records with Price less than a specific value
To check the records with Price less than a specific value, use $lt. Let us create a collection with documents −
> db.demo728.insertOne({Price:75}); { "acknowledged" : true, "insertedId" : ObjectId("5eab413c43417811278f589b") } > db.demo728.insertOne({Price:59}); { "acknowledged" : true, "insertedId" : ObjectId("5eab414043417811278f589c") } > db.demo728.insertOne({Price:79}); { "acknowledged" : true, "insertedId" : ObjectId("5eab414543417811278f589d") } > db.demo728.insertOne({Price:89}); { "acknowledged" : true, "insertedId" : ObjectId("5eab414843417811278f589e") }
Display all documents from a collection with the help of find() method −
> db.demo728.find();
This will produce the following output −
{ "_id" : ObjectId("5eab413c43417811278f589b"), "Price" : 75 } { "_id" : ObjectId("5eab414043417811278f589c"), "Price" : 59 } { "_id" : ObjectId("5eab414543417811278f589d"), "Price" : 79 } { "_id" : ObjectId("5eab414843417811278f589e"), "Price" : 89 }
Following is the query to find records based on a condition −
> db.demo728.find({Price:{$lt:80}});
This will produce the following output −
{ "_id" : ObjectId("5eab413c43417811278f589b"), "Price" : 75 } { "_id" : ObjectId("5eab414043417811278f589c"), "Price" : 59 } { "_id" : ObjectId("5eab414543417811278f589d"), "Price" : 79 }
Advertisements