1先添加mongodb -> MongoDB.Driver 驱动
//mongodb 只有数据库->集合-》文档
// 使用连接字符串连接
var client = new MongoClient("mongodb://192.168.0.7:27017");
//获取database
var mydb = client.GetDatabase("test");
//获取collection
var collection = mydb.GetCollection<BsonDocument>("user");
//待添加的document
var doc = new BsonDocument{
{ "_id",3 },
{ "name", "李四" },
{ "age", 24 },
{ "company","冰川"}
};
//InsertOne()添加单条docment
collection.InsertOne(doc);
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280355.html