2017-04-10 42 views
0

找到與當前最高價格的ID(一個或多個)找到具有最高值的ID(「當前」)mongon:在另一列

這裏是數據的樣本:

{ 
    "_id": "1043817906", 
    "Currently": 6.00 
} 

我只知道代碼

db.xxx.aggregate({ $group : { _id:null, max: { $max : "$Currently" }}}); 

這樣,結果是

{ 「_id」:空, 「最大」:18000}

但我也想知道「_id」號碼(最大「當前」)。

謝謝!

回答

0

你可以排序currently場返回第一個文件:

db.collection.aggregate([ 
    {$sort: {"Currently": -1}}, 
    {$limit: 1}, 
    {$project: {max: "$Currently"}} 
])