我在 MongoDB 中有数千个文档,其中一些示例如下:
{"title":"Foo", "hash": "1234567890abcedf", "num_sold": 49,
"created": "2013-03-09 00:00:00"}
{"title":"Bar", "hash": "1234567890abcedf", "num_sold": 55,
"created": "2013-03-11 00:00:00"}
{"title":"Baz", "hash": "1234567890abcedf", "num_sold": 55,
"created": "2013-03-10 00:00:00"}
{"title":"Spam", "hash": "abcedef1234567890", "num_sold": 20,
"created": "2013-03-11 00:00:00"}
{"title":"Eggs", "hash": "abc1234567890def", "num_sold": 20,
"created": "2013-03-11 00:00:00"}
是否可以选择具有 distinct且hash
具有最大值的所有文档,num_sold
如果有多个具有相同的文档,请从该字段中num_sold
选择最新的文档。created
我使用 PyMongo 作为客户端。