样品采集:
#0
{ '_id' : ObjectId("5291c70419181fe0f8ea9ff8"),
'state' : 'CA',
'hitCount' : 100
}
#1
{ '_id' : ObjectId("5d3443fdf4441fe0f8ea9kk2"),
'state' : 'CA',
'hitCount' : 10
}
#2
{ '_id' : ObjectId("52943242344fe0f8ea9ff348"),
'state' : 'CA',
'hitCount' : 1
}
#3
{ '_id' : ObjectId("5291c7er89482942342344a"),
'state' : 'NY',
'hitCount' : 100
}
#4
{ '_id' : ObjectId("342834723942sdfsafa334"),
'state' : 'NY',
'hitCount' : 10
}
#5
{ '_id' : ObjectId("ewr8943459n0ads1231411"),
'state' : 'NY',
'hitCount' : 1
}
我将如何返回文档 0、1、3 和 4 - 按状态分组并返回前 2 个 hitCount。
我一直在尝试使用聚合组功能。我想我已经接近了,但我的解决方案仍然需要大量的客户端工作——我带入所有文件,然后得到我需要的文件。这绝对不会扩展,因此需要一些帮助来修复它。
我正在使用 pymongo。