I inherited some code that now when I compile the compiler issues warnings. I have read help files but they seem like trying to solve the problem with an encyclopedia. There is alot of information but now examples, I have the following "legacy" code
string mongoConnectionString = ConfigurationManager.AppSettings["MongoConnectionString"];
MongoServer server = MongoServer.Create(mongoConnectionString);
MongoDatabase db = null;
if (!server.DatabaseExists("database"))
{
db = MongoDatabase.Create(server.Settings, "database");
}
else
{
db = server.GetDatabase("database");
}
The error/warnings are as follows:
1>C:\Program.cs(2635,34,2635,75): warning CS0618: 'MongoDB.Driver.MongoServer.Create(string)' is obsolete: 'Use MongoClient.GetServer instead.'
1>C:\Program.cs(2640,22,2640,73): warning CS0618: 'MongoDB.Driver.MongoDatabase.Create(MongoDB.Driver.MongoServerSettings, string)' is obsolete: 'Use MongoClient, GetServer and GetDatabase instead.'
So one of the problems is that Create is obsolete and I should use GetServer instead. The problem is that there is no static method GetServer on the MongoClient class. So that says I need to create a MongoClient instance. How is that done? Next error indicates that MongoDatabase.Create is obsolete and I should use MongoClient, GetServer, and GetDatabase instead. Even if I knew how to create a client then a server I still would only be getting a database not creating it. Any help with this conversion would be greatly appreciated. Thank you.