How to close cursor in MongoKit
Asked Answered
G

1

6

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?

Galimatias answered 22/3, 2011 at 13:50 Comment(0)
T
9

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
Trigonous answered 22/3, 2011 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.