How to get the document with max value for a field with map-reduce in pymongo?

前端 未结 1 625
旧巷少年郎
旧巷少年郎 2020-12-19 00:50

How do I find the document with the maximum uid field with map-reduce in pymongo?

I have tried the following but it prints out blanks:

f         


        
相关标签:
1条回答
  • 2020-12-19 01:28

    You can use find_one to find the doc with the maximum uid by sorting on that field descending:

    db.things.find_one(sort=[("uid", -1)])
    

    or using the defined constant:

    db.things.find_one(sort=[("uid", pymongo.DESCENDING)])
    
    0 讨论(0)
提交回复
热议问题