Introduction
Below code snippet contains full code for getting MongoDb client reference.
- try
- {
- Console.WriteLine("Creating Client..........");
- MongoClient client = null;
- client = new MongoClient(connectionString);
- Console.WriteLine("Client Created Successfuly........");
- Console.WriteLine("Client: " + client.ToString());
- }
- catch (Exception ex)
- {
- Console.WriteLine("Filed to Create Client.......");
- Console.WriteLine(ex.Message);
- }
- try
- {
- Console.WriteLine("Getting Servicer object......");
- MongoServer server = client.GetServer();
- Console.WriteLine("Server object created Successfully....");
- Console.WriteLine("Server :" + server.ToString());
- }
- catch (Exception ex)
- {
- Console.WriteLine("Filed to getting Server Details");
- Console.WriteLine(ex.Message);
- }
-