I'm doing a python script that writes some data to a mongodb. I need to close the connection and free some resources, when finishing.
How is that done in Python?
Use close()
method on your MongoClient
instance:
client = pymongo.MongoClient()
# some code here
client.close()
close()
is an alias for disconnect()
method:
Disconnecting will close all underlying sockets in the connection pool. If this instance is used again it will be automatically re-opened.