c# - 'MongoDB.Driver.MongoClient' does not contain a definition for 'GetServer' ...first argument of type 'MongoDB.Driver.MongoClient' could be found -


i'm trying familiar writing mongodb c# programs. i've set code following suggestions http://mongodb.github.io/mongo-csharp-driver/1.11/getting_started/

i'm trying run program getting error "'mongodb.driver.mongoclient' not contain definition 'getserver' , no extension method 'getserver' accepting first argument of type 'mongodb.driver.mongoclient' found". may help?

thanks in advance, tien.

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using mongodb.bson; using mongodb.driver; //additionally, add 1 or more of these using statements: //using mongodb.driver.builders; //error rebuilding when statement active: "using generic type 'mongodb.driver.builders<tdocument>' requires 1 type arguments //using mongodb.driver.gridfs; using mongodb.driver.linq; //using mongodb.driver.mongoclient; //error rebuilding when statement active "a using namespace directive can applied namespaces; 'mongodb.driver.mongoclient' type not namespace   namespace write2mongodb {     public class entity     {         public objectid id { get; set; }         public string name { get; set; }     }   class program {     static void main(string[] args)     {         #region full sample program         var connectionstring = "mongodb://localhost";         var client = new mongoclient(connectionstring);         var server = client.getserver();         var database = server.getdatabase("test");         var collection = database.getcollection<entity>("entities");          var entity = new entity { name = "tom" };         collection.insert(entity);         var id = entity.id;          var query = query<entity>.eq(e => e.id, id);         entity = collection.findone(query);          entity.name = "dick";         collection.save(entity);          var update = update<entity>.set(e => e.name, "harry");         collection.update(query, update);          collection.remove(query);           #endregion           console.readkey();     } } 

}

getserver() has been deprecated, retrieve database client so:

var client = new mongoclient("mongodb://localhost"); var database = client.getdatabase("test"); var collection = database.getcollection<entity>("entities"); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -