我正在编写一个将一些数据写入 mongodb 的 python 脚本。 完成后,我需要关闭连接并释放一些资源。
这是如何在 Python 中完成的?
最佳答案
使用 close()
MongoClient
实例上的方法:
client = pymongo.MongoClient()
# some code here
client.close()
Cleanup client resources and disconnect from MongoDB.
End all server sessions created by this client by sending one or more endSessions commands.
Close all sockets in the connection pools and stop the monitor threads.
https://stackoverflow.com/questions/18401015/