现在的位置: 首页 > 综合 > 正文

C# , mongodb ,study

2012年11月16日 ⁄ 综合 ⁄ 共 686字 ⁄ 字号 评论关闭

//MongoDB服务器连接串

string connectionString = ConfigurationManager.ConnectionStrings["concString"].ToString();
MongoServer server = MongoServer.Create(connectionString);

//连接到mydb数据库
MongoDatabase db = server.GetDatabase("mydb");

//连接到testzj集合
MongoCollection collection = db.GetCollection("testzj");

//创建对象stu1
BsonDocument stu1 = new BsonDocument
{
{"total_variable_characters2","0018"},
{"fixed_weather_station_usaf_master_station_catalog_identifier2","128970"},
{"fixed_weather_station_ncdc_wban_identifier2","256542"}
};

//创建对象stu2

BsonDocument stu2 = new BsonDocument();

stu2.Add("abc", 2);
stu2.Add("efg", "hello world");

//将对象stu1 and stu2放到集合students中
collection.Insert(stu1);

collection.Insert(stu2);

MessageBox.Show("插入成功!");

抱歉!评论已关闭.