
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to get values greater than a specific value from an embedded list in MongoDB?
To get values greater than a specific value, use $gt along with find(). Let us create a collection with documents −
> db.demo317.insertOne( ... {'id':101, ... 'details':[{'Score':78,Name:"Chris"}, ... {'Score':88,Name:"David"} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e50e69cf8647eb59e562060") } > db.demo317.insertOne( ... {'id':102, ... 'details':[{'Score':90,Name:"Chris"}, ... {'Score':91,Name:"David"} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e50e6adf8647eb59e562061") }
Display all documents from a collection with the help of find() method −
> db.demo317.find();
This will produce the following output −
{ "_id" : ObjectId("5e50e69cf8647eb59e562060"), "id" : 101, "details" : [ { "Score" : 78, "Name" : "Chris" }, { "Score" : 88, "Name" : "David" } ] } { "_id" : ObjectId("5e50e6adf8647eb59e562061"), "id" : 102, "details" : [ { "Score" : 90, "Name" : "Chris" }, { "Score" : 91, "Name" : "David" } ] }
Following is the query to use $gt on the embedded list in MongoDB to get score records greater than 89 −
> db.demo317.find({"details.Score" :{"$gt": 89}});
This will produce the following output −
{ "_id" : ObjectId("5e50e6adf8647eb59e562061"), "id" : 102, "details" : [ { "Score" : 90, "Name" : "Chris" }, { "Score" : 91, "Name" : "David" } ] }
- Related Articles
- MongoDB query to match documents with array values greater than a specific value
- Get specific elements from embedded array in MongoDB?
- How to select values less than or greater than a specific percentile from an R data frame column?
- MongoDB query to get specific list of names from documents where the value of a field is an array
- Match MongoDB documents with field value greater than a specific number and fetch them?
- How do I get a value array (instead a json array) greater than 50 in MongoDB?
- How to get embedded data in a MongoDB document?
- How to get items with a specific value from documents using MongoDB shell?
- Return specific MongoDB embedded document
- Is it possible to return a list of specific values from a query in MongoDB?
- How to select where sum of fields is greater than a value in MongoDB?
- Is it possible to return a list of specific values from a MongoDB query?
- Python program to check if all the values in a list that are greater than a given value
- C# program to check if all the values in a list that are greater than a given value
- Python - Number of values greater than K in list

Advertisements