MongoDB C#连接/断开连接(官方驱动程序) [英] MongoDB C# connections/disconnections (Official driver)

查看:421
本文介绍了MongoDB C#连接/断开连接(官方驱动程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我我如何必须通过官方C#驱动程序连接/断开与MongoDB的连接?问题很简单,问题乍一看并不重要,但是:

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)我需要自己调用Disconnect方法,还是会被Dispose之类的方法关闭?

1) Do I need to call Disconnect method by myself, or it will be closed by some method like Dispose?

2)每当我需要向Mongo提出请求时,都需要连接吗?还是保留Connection会更好?

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)重新连接方法有用吗?您使用它吗?

3) Is method Reconnect are useful? Do you use it?

还有其他建议吗?

非常感谢您!

更新: 我的问题是关于连接的生命周期;)

Update: My question is about the life cycle of connections;)

推荐答案

官方驱动程序在内部维护连接池.您无需处理任何连接,甚至无需建立新连接.

The official driver maintains a connection pool internally. You do not need to dispose of any connections or even establish new connections.

请求连接如此简单

MongoServer.Create(mongoConnectionString)

文档中找到有关驱动程序的更多信息.

这篇关于MongoDB C#连接/断开连接(官方驱动程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆