close() never close connections in pymongo?

一笑奈何 提交于 2019-12-22 04:00:22

问题


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']

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?


回答1:


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



来源:https://stackoverflow.com/questions/20613339/close-never-close-connections-in-pymongo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!