- 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
Get only the FALSE value with MongoDB query
To get only the FALSE value, let us first create a collection with documents. One of the fields is isEnable that is having TRUE or FALSE values as shown below
> db.translateDefinitionDemo.insertOne({"_id":10,"StudentName":"Larry","isEnable":true}); { "acknowledged" : true, "insertedId" : 10 } > db.translateDefinitionDemo.insertOne({"_id":20,"StudentName":"Chris","isEnable":false}); { "acknowledged" : true, "insertedId" : 20 } > db.translateDefinitionDemo.insertOne({"_id":30,"StudentName":"Robert","isEnable":true}); { "acknowledged" : true, "insertedId" : 30 } > db.translateDefinitionDemo.insertOne({"_id":40,"StudentName":"Sam","isEnable":false}); { "acknowledged" : true, "insertedId" : 40 } > db.translateDefinitionDemo.insertOne({"_id":50,"StudentName":"Mike","isEnable":true}); { "acknowledged" : true, "insertedId" : 50 }
Following is the query to display all the documents from a collection with the help of find() method
> db.translateDefinitionDemo.find().pretty();
This will produce the following output
{ "_id" : 10, "StudentName" : "Larry", "isEnable" : true } { "_id" : 20, "StudentName" : "Chris", "isEnable" : false } { "_id" : 30, "StudentName" : "Robert", "isEnable" : true } { "_id" : 40, "StudentName" : "Sam", "isEnable" : false } { "_id" : 50, "StudentName" : "Mike", "isEnable" : true }
Following is the query to get only the FALSE value in MongoDB
> db.translateDefinitionDemo.find({ "_id" : { "$in" : [10, 20, 30,40,50] }, "isEnable" : { "$ne" : true } }).pretty();
This will produce the following output
{ "_id" : 20, "StudentName" : "Chris", "isEnable" : false } { "_id" : 40, "StudentName" : "Sam", "isEnable" : false }
Advertisements