![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Set $gt condition in MongoDB $and
The $and performs a logical AND operation on an array of one or more expressions. Let us create a collection with documents −
> db.demo680.insertOne({Values:40}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4461b04263e90dac943fe") } > db.demo680.insertOne({Values:70}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4461e04263e90dac943ff") } > db.demo680.insertOne({Values:[80,30]}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4462a04263e90dac94400") } > db.demo680.insertOne({Values:20}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4463304263e90dac94401") }
Display all documents from a collection with the help of find() method −
> db.demo680.find();
This will produce the following output −
{ "_id" : ObjectId("5ea4461b04263e90dac943fe"), "Values" : 40 } { "_id" : ObjectId("5ea4461e04263e90dac943ff"), "Values" : 70 } { "_id" : ObjectId("5ea4462a04263e90dac94400"), "Values" : [ 80, 30 ] } { "_id" : ObjectId("5ea4463304263e90dac94401"), "Values" : 20 }
Following is the query to use $gt in $and −
> db.demo680.find({$and : [{Values:{$gt:60}}, {Values:30}]})
This will produce the following output −
{ "_id" : ObjectId("5ea4462a04263e90dac94400"), "Values" : [ 80, 30 ] }
Advertisements