//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("插入成功!");