Getting Reference of MongoDB Server

Introduction
Below code snippet contains full code for getting MongoDb client reference.
  1. try  
  2. {  
  3. Console.WriteLine("Creating Client..........");  
  4. MongoClient client = null;  
  5. client = new MongoClient(connectionString);  
  6. Console.WriteLine("Client Created Successfuly........");  
  7. Console.WriteLine("Client: " + client.ToString());  
  8. }  
  9. catch (Exception ex)  
  10. {  
  11. Console.WriteLine("Filed to Create Client.......");  
  12. Console.WriteLine(ex.Message);  
  13. }  
  14. try  
  15. {  
  16. Console.WriteLine("Getting Servicer object......");  
  17. MongoServer server = client.GetServer();  
  18. Console.WriteLine("Server object created Successfully....");  
  19. Console.WriteLine("Server :" + server.ToString());  
  20. }  
  21. catch (Exception ex)  
  22. {  
  23. Console.WriteLine("Filed to getting Server Details");  
  24. Console.WriteLine(ex.Message);  
  25. }  
  26.   
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now