问题
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