
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to query MongoDB a value with $lte, $in and $not to fetch specific values?
Let us first create a collection with documents −
> db.demo130.insertOne( ... { ... ... "PlayerDetails":[{Score:56},{Score:78},{Score:89},{Score:97}] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e3065bf68e7f832db1a7f6d") } > db.demo130.insertOne( ... { ... ... "PlayerDetails":[{Score:45},{Score:56}] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e3065c068e7f832db1a7f6e") }
Display all documents from a collection with the help of find() method −
> db.demo130.find();
This will produce the following output −
{ "_id" : ObjectId("5e3065bf68e7f832db1a7f6d"), "PlayerDetails" : [ { "Score" : 56 }, { "Score" : 78 }, { "Score" : 89 }, { "Score" : 97 } ] } { "_id" : ObjectId("5e3065c068e7f832db1a7f6e"), "PlayerDetails" : [ { "Score" : 45 }, { "Score" : 56 } ] }
Following is the query to fetch −
> db.demo130.find({ ... "PlayerDetails.Score": { ... "$eq": 56, ... "$not": { "$gt": 56} ... } ... })
This will produce the following output −
{ "_id" : ObjectId("5e3065c068e7f832db1a7f6e"), "PlayerDetails" : [ { "Score" : 45 }, { "Score" : 56 } ] }
- Related Questions & Answers
- How to query MongoDB a value with $lte and $in?
- Query an array in MongoDB to fetch a specific value
- MongoDB query to fetch array values
- MongoDB aggregation to fetch documents with specific field value?
- MongoDB query to fetch a specific document rom documents with field value set using NumberInt()?
- MongoDB query to determine if a specific value does not exist?
- MongoDB query to match documents with array values greater than a specific value
- Fetch specific field values in MongoDB
- MongoDB query to implement nor query to fetch documents except a specific document
- MongoDB query to group records and display a specific value with dot notation
- Accessing array values in a MongoDB collection to fetch a specific document
- MongoDB query to sum specific key values with terminal commands?
- JavaScript fetch a specific value with eval()?
- How to filter some fields in objects and fetch a specific subject name value in MongoDB?
- MongoDB query to pull a specific value from a document
Advertisements