How to close cursor in MongoKit

大城市里の小女人 提交于 2019-12-10 13:34:53

问题


I'm using MongoKit to perform iteration over a huge amount of data.

During this process my cursor becomes invalid, and I'm getting

OperationFailure: cursor id '369397057360964334' not valid at server

I've read in mailing lists that I can pass parameter timeout=False to .find() method, but PyMongo FAQ says that I vave to take care of closing cursor myself.

But I didn't find methods in MongoKit for that.

Do I need to close cursor by hand, and if yes - how can I do it?


回答1:


You'll have to close the cursor since the MongoDB server won't time out the cursor for you, given that you specifically asked it not to.

simply call del on your cursor. The default pymongo implementation for __del__ will notify the server to kill the cursor.

Assuming something like:

cursor = db.test.find(timeout=False)

Simply do this when you're done:

del cursor


来源:https://stackoverflow.com/questions/5392318/how-to-close-cursor-in-mongokit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!