How to convert a pymongo.cursor.Cursor into a dict?

前端 未结 6 1442
日久生厌
日久生厌 2020-12-02 16:18

I am using pymongo to query for all items in a region (actually it is to query for all venues in a region on a map). I used db.command(SON()) before to search i

6条回答
  •  一个人的身影
    2020-12-02 17:06

    Map function is fast way to convert big collection

    from time import time
    
    
    cursor = db.collection.find()
    
    def f(x):
        return x['name']
    
    t1 = time()
    blackset = set(map(f, cursor))
    print(time() - t1)
    

提交回复
热议问题