MongoDB C# connections/disconnections (Official driver)

南楼画角 提交于 2019-12-07 01:40:13

问题


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;)


回答1:


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

MongoServer.Create(mongoConnectionString)

Read more at the doc site for the driver.



来源:https://stackoverflow.com/questions/5352018/mongodb-c-sharp-connections-disconnections-official-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!