How to make pymongo's find() return a list?

后端 未结 1 726
栀梦
栀梦 2020-12-16 09:00

Pymongo returns a cursor with it I am able to iterate over the results and append their documents to a list. Is there a way to get the result documents in a list directly? T

相关标签:
1条回答
  • 2020-12-16 09:38

    The following code will convert the entire result set (Cursor) into a list:

    myresults = list(mydb.mycollection.find())
    

    This is fine for relatively small result sets, as you are pulling everything into memory.

    0 讨论(0)
提交回复
热议问题