I have mongodb collection like:
[{
"name": "a",
"price": 130
},
{
"name": "b",
"price": 90
},
{
"name": "c",
"price": 150
},
{
"name": "e",
"price": 170
},
{
"name": "g",
"price": 135
}]
I need a query to get max three "price" from this collection.
3
Answers
db.collection.find().sort({price:-1}).limit(3)
Query
Playmongo
Use .sort() and .limit() for that
sort in ascending order and then use limit