close()永远不会在pymongo中关闭连接? [英] close() never close connections in pymongo?

查看:1099
本文介绍了close()永远不会在pymongo中关闭连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MongoDB,并通过pymongo连接到它.这是我的代码:

I use MongoDB and I connect to it through pymongo. Here's my code:

>>> import pymongo
>>> con=pymongo.Connection('localhost',27017)
>>> con.database_names()
['local', 'bookdb']
>>> con.close()
>>> con.database_names()
['local', 'bookdb']

我使用con.close()断开与MongoDB的连接,但是此后,我仍然可以使用con.database_names()来查看数据库列表.为什么?它永远不会断开与MongoDB服务器的连接.为什么close()不起作用?

I use con.close() to disconnect to the MongoDB, but after that, I can still use con.database_names() to see the list of the databases. Why? it never disconnect to the MongoDB server. Why the close() not work?

推荐答案

只需快速,详细地阅读文档即可.

Just read the docs, faster and more detailed.

如果再次使用此实例,它将自动重新打开.

If this instance is used again it will be automatically re-opened.

http://api. mongodb.org/python/current/api/pymongo/connection.html

这篇关于close()永远不会在pymongo中关闭连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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