List comprehension with cursor from pymongo
问题 Here is my pymongo code: client = MongoClient('localhost', 27017) db = client['somedb'] collection = db.somecollection return_obj = collection.find({"field1":"red"}) #First print statement print([item['field1'] for item in return_obj]) #Second print statement print([item['field1'] for item in return_obj]) The first print statement produces non-empty list, while the second one produces empty list. As if I have to reset an index on return_obj. Any ideas? 回答1: This is the correct behaviour, this