mongodb的用法
关于新版(2.***)的c#用法,网上基本没有。昨天折腾半天,去构造server,发现现在新版本不需要了,文档是这样的,大概意思,无需像原来那样获取server,直接从client获取db就行了。
https://github.com/mongodb/mongo-csharp-driver
http://www.cnblogs.com/imeiba/archive/2016/07/12/5663088.html
using MongoDB.Bson; using MongoDB.Driver;
var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("foo"); var collection = database.GetCollection<BsonDocument>("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"]); }