MongoEngine - 如何关闭游标

4
我正在使用timeout=False查询数据库。
cursor = Users.objects.timeout(False)

文档说明如果创建了一个没有超时的光标,那么必须手动关闭它。

问题是,我在使用完光标后如何关闭它?
我在文档或光标对象中都没有找到关闭功能。

** 编辑 **
这是dir(cursor)的输出:

['_BaseQuerySet__dereference', '__bool__', '__call__', '__class__', '__deepcopy__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getstate__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__' '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_as_pymongo', '_as_pymongo_coerce', '_auto_dereference', '_batch_size', '_chainable_method', '_class_check', '_collection', '_collection_obj', '_cursor', '_cursor_args', '_cursor_obj', '_dereference', '_document', '_ensure_indexes', '_fields_to_dbfields', '_get_as_pymongo', '_get_order_by', '_get_scalar', '_has_data', '_has_more', '_hint', '_initial_query', '_item_frequencies_exec_js', '_item_frequencies_map_reduce', '_iter', '_iter_results', '_len', '_limit', '_loaded_fields', '_max_time_ms', '_mongo_query', '_none', '_ordering', '_populate_cache', '_query', '_query_obj', '_read_preference', '_result_cache', '_scalar', '_search_text', '_skip', '_slave_okay', '_snapshot', '_sub_js_fields', '_timeout', '_where_clause', 'aggregate', 'all', 'all_fields', 'as_pymongo', 'average', 'batch_size', 'clone', 'clone_into', 'comment', 'count', 'create', 'delete', 'distinct', 'ensure_index', 'exclude', 'exec_js', 'explain', 'fields', 'filter', 'first', 'from_json', 'get', 'hint', 'in_bulk', 'insert', 'item_frequencies', 'limit', 'map_reduce', 'max_time_ms', 'modify', 'next', 'no_cache', 'no_dereference', 'no_sub_classes', 'none', 'only', 'only_fields', 'order_by', 'read_preference', 'rewind', 'scalar', 'search_text', 'select_related', 'skip', 'slave_okay', 'snapshot', 'sum', 'timeout', 'to_json', 'update', 'update_one', 'upsert_one', 'using', 'values_list', 'where', 'with_id']

谢谢。

使用close()方法? - roganjosh
@roganjosh 没有关闭方法。 - Drxxd
现在你有两个人链接到完全相同的事情。如果这不起作用,那么你需要更具体地说明你的问题,说明这里发生了什么。 - roganjosh
2
https://groups.google.com/forum/#!topic/mongodb-user/CrPTP3Rye5I - roganjosh
1
@roganjosh 谢谢!这个回答解决了我的问题。 - Drxxd
显示剩余3条评论
1个回答

1
这里使用 del

cursor = Users.objects.timeout(False)
del cursor

这将通知服务器杀死光标。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接