0
我有以下查詢:
HOST_USAGE.aggregate([{
'$match': {'sysstat.host.nodename': host}
}, {
'$project': {'ts': '$sysstat.host.statistics.timestamp'}
}, {
'$unwind': '$ts'
}, {
'$unwind': '$ts.cpu-load-all.cpu'
}, {
'$group': {
'_id': 0,
'all-usr': {'$max': '$ts.cpu-load-all.cpu.usr'}
}
}])
然而,有,我想抓住一個附加字段,$sysstat.host.statistics.timestamp[*].time
我我試過了,
'$group': {
'_id': 0,
'all-usr': {'$max': '$ts.cpu-load-all.cpu.usr'},
'time': '$ts.time'
}
但是這個gi一個錯誤:pymongo.errors.OperationFailure: exception: the group aggregate field 'time' must be defined as an expression inside an object
。我怎樣才能$group
某些字段,並將其他字段投影到返回的數據集?
謝謝,但我想要做的是實際抓住'$ max'發現的不同時間。這是可能的,還是我需要重新整理我的查詢? – MrDuk