python - MongoEngine - 如何关闭游标

标签 python mongodb mongoengine

我正在使用 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']

谢谢。

最佳答案

这里使用del:

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

这将通知服务器终止光标

关于python - MongoEngine - 如何关闭游标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47012374/

相关文章:

java - ExecutorService 中对 MongoRepository 的调用无法完成

mongodb - MongoEngine 中的 "reload()"是什么

python - 如何在两个numpy数组上找到满足不同条件的行数

python - Celery 的异步替换

python - Django 测试 : separate unit and integration tests on Travis CI

javascript - 比较 Mongo 中的两个引用?

php - PHP 中是否有类似于 mongoid 的 MongoDB ORM?

python - 如何从训练图像及其标签创建 caffemodel 文件?

MongoDB 按结果限制分组

Mongoengine检查对象是否存在而不获取对象