Pymongo: iterate over all documents in the collection

后端 未结 4 1305
孤城傲影
孤城傲影 2021-02-13 18:26

I am using PyMongo and trying to iterate over (10 millions) documents in my MongoDB collection and just extract a couple of keys: \"name\" and \"address\", then output them to .

4条回答
  •  别跟我提以往
    2021-02-13 18:51

    The find() methods returns a PyMongo cursor, which is a reference to the result set of a query.

    You have to de-reference, somehow, the reference(address).

    After that, you will get a better understanding how to manipulate/manage the cursor.

    Try the following for a start:

    result = db.*collection_name*.find()
    print(list(result)) 
    

提交回复
热议问题