nosql-mongodb-api使用
作者:互联网
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,new,添加,mydb 来源: https://www.cnblogs.com/RaymonGoGo/p/16583749.html