如何在MongoKit中关闭游标 [英] How to close cursor in MongoKit

查看:223
本文介绍了如何在MongoKit中关闭游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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

:cursor id'369397057360964334'在服务器上无效

我在邮件列表中读取了我可以传递的参数 timeout = False .find()方法,但 PyMongo常见问题说我自己关心光标。

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.

但我没有在MongoKit中找到方法。

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?

推荐答案

您必须关闭游标,因为MongoDB服务器不会为您超时游标,特别要求它不要。

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.

只需在光标上调用 del 即可。 __ del __ 的默认pymongo实现将通知服务器终止游标。

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

假设像:

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

完成后只需执行此操作:

Simply do this when you're done:

del cursor

这篇关于如何在MongoKit中关闭游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆