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);
标签:nosql,mongodb,collection,api,var,添加
From: https://www.cnblogs.com/RaymonGoGo/p/16583749.html