How do you manage connections to mongodb from C#? -


How can you manage the Mangodeb connection from C #? Close after use (CRUD)? Or can you keep the connection open at all times?

This is my code to keep things perspective:

  string connection string = "mongodb: // localhost"; MongoClient Client = new Mongo Client (connectionString); MongoServer Server = client.GetServer (); MongoDatabase database = server.GetDatabase ("UsersDb");  

Replica set to be added to driver in order to manage stuff, since 1.7 is. It is considered singleton and thread-protected you can always get MongoServer from it.
You do not have to worry about closing the connection. See this for more information, it is managed by the driver.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -