// MongoDB服务器 连接串
const string connectionString = "mongodb://127.0.0.1";
var server = MongoServer.Create(connectionString);
// 连接到 mongodb_c_demo 数据库
var db = server.GetDatabase("mongodb_c_demo");
// 获取集合 fruit
var collection = db.GetCollection("fruit");
// 创建对象 fruit_1
var fruit1 = new BsonDocument
{
{ "webste", "http://www.my400800.cn " },
{ "name", "400电话 " }
};
// 创建对象 fruit_2
var fruit2 = new BsonDocument
{
{ " webste ", "http://www.hrxc.net" },
{ " name ", "华仁信诚 " }
};
// 将对象 fruit_1 放到集合 fruit 中
collection.Insert(fruit1);
// 将对象 fruit_2 放到集合 fruit 中
collection.Insert(fruit2);
C# 连接MongoDB服务器 并插入数据
最新推荐文章于 2023-04-19 11:39:20 发布