MongoDB C# 连接/断开(官方驱动程序)
请告诉我如何通过官方 C# 驱动程序连接/断开到 MongoDB?问题很简单,乍看之下问题很微不足道,但是:
1)我是否需要自己调用 Disconnect 方法,或者它会被诸如 Dispose 之类的方法关闭?
2)每次需要向Mongo发出请求时都需要连接吗?还是保持连接会更好?
3)Reconnect方法有用吗?你用它吗?
还有其他建议吗?
非常感谢!!!
更新: 我的问题是关于连接的生命周期;)
Please tell me how I must connect/disconnect to MongoDB via official C# driver? Question is simple and problem is trivial for first look, but:
1) Do I need to call Disconnect method by myself, or it will be closed by some method like Dispose?
2) Do I need to Connect every time when I need to make request to Mongo? Or it will be better to keep Connection?
3) Is method Reconnect are useful? Do you use it?
Any additional advice?
Thank you very much!!!
Update:
My question is about the life cycle of connections;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
官方驱动内部维护了一个连接池。您不需要处置任何连接,甚至不需要建立新连接。
请求连接就这么简单,
请阅读 doc 了解更多信息驱动程序的网站。
The official driver maintains a connection pool internally. You do not need to dispose of any connections or even establish new connections.
Requesting a connection is as easy as this
Read more at the doc site for the driver.