Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close cursor in MongoKit

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 myself, and if yes - how can I do it?

like image 450
cleg Avatar asked Mar 22 '11 13:03

cleg


1 Answers

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
like image 70
MC78 Avatar answered Oct 10 '22 07:10

MC78