MongoClient is added to the driver since 1.7, to manage replica set stuff. It's supposed to be singleton and is thread-safe. You can always get MongoServer from it.
You don't need to worry about closing connections. It's managed by the driver.
Refer to the tutorial for more information.
How do you manage connections to mongodb from C#?
-
08-07-2023 - |
Pregunta
How do you manage mongodb connection from c#? close after use(CRUD)? or put the connection open all the time?
to put things in perspective here is my code:
string connectionString = "mongodb://localhost";
MongoClient client = new MongoClient(connectionString);
MongoServer server = client.GetServer();
MongoDatabase database = server.GetDatabase("UsersDb");
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow