Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoServer does not contain a definition for 'Create'

Tags:

c#

mongodb

I am getting the MongoServer does not contain a definition for 'Create' exception while compiling the below code. Please help me on this.

Libraries and versions

  • MongoDB.Bson 2.0.0
  • MongoDB.Driver 2.0.0
  • MongoDB.Driver.Core 2.0.0
List<Info> names = new List<Info>();
String name = "";
MongoServer server = MongoServer.Create(
    ConfigurationManager.AppSettings["connectionString"]);
MongoDatabase myDB = server.GetDatabase("ES");
MongoCollection<Info> Persons = myDB.GetCollection<Info>("MyCollection");
foreach (Info Aperson in Persons.FindAll())
{
    name = name + " " + Aperson.Name;
    names.Add(Aperson);
}
like image 694
user297222 Avatar asked Apr 30 '15 23:04

user297222


1 Answers

The MongoServer.Create() method was removed in version 2.0. It has been deprecated since at least version 1.7.

Instead, use MongoClient. To get access to the MongoServer, use MongoClient.GetServer()

MongoClient client = new MongoClient(
    ConfigurationManager.AppSettings["connectionString"]);
MongoServer server = client.GetServer();
like image 185
gilly3 Avatar answered Oct 12 '22 22:10

gilly3