Find the ID(s) with the highest current price.("Currently")
Here is a sample of the data:
{
"_id": "1043817906",
"Currently": 6.00
}
I just know the code
db.xxx.aggregate({ $group : { _id:null, max: { $max : "$Currently" }}});
In this way, the result is
{ "_id" : null, "max" : 18000 }
But i also want know the "_id" number (with maximum "Currently").
Thanks!
you could sort on currently
field and return the first document:
db.collection.aggregate([
{$sort: {"Currently": -1}},
{$limit: 1},
{$project: {max: "$Currently"}}
])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.