Get only the FALSE value with MongoDB query

MongoDBBig Data AnalyticsDatabase

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 }
raja
Published on 11-Apr-2019 09:15:11
Advertisements