Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB C# connections/disconnections (Official driver)

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

like image 896
Edward83 Avatar asked Mar 18 '11 12:03

Edward83


1 Answers

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.

like image 117
Bryan Migliorisi Avatar answered Sep 20 '22 16:09

Bryan Migliorisi