关于新版(2.***)的c#用法,网上基本没有。昨天折腾半天,去构造server,发现现在新版本不需要了,文档是这样的,大概意思,无需像原来那样获取server,直接从client获取db就行了。
using MongoDB.Bson;using MongoDB.Driver;
var client = new MongoClient("mongodb://localhost:27017");var database = client.GetDatabase("foo");var collection = database.GetCollection("bar");await collection.InsertOneAsync(new BsonDocument("Name", "Jack"));var list = await collection.Find(new BsonDocument("Name", "Jack")) .ToListAsync();foreach(var document in list){ Console.WriteLine(document["Name"]);}