C# mongohelper的初始化及账户密码设置

 1 MongoClientSettings mongoSettings = new MongoClientSettings();
 2 TimeSpan t = new TimeSpan(100);
 3 mongoSettings.ConnectTimeout = t;//设置连接超时时长
 4 mongoSettings.MaxConnectionPoolSize = 2000;//设置连接池最大连接数
 5 MongoCredentials credentials = MongoCredentials.Create("用户名", "密码");//添加用户名、密码
 6 mongoSettings.DefaultCredentials = credentials;
 7 mongoSettings.Server =new MongoServerAddress("192.168.1.1",27017);//服务器地址
 8 mongoSettings.ReadPreference = new ReadPreference(ReadPreferenceMode.Primary);
 9 mongoClient = new MongoClient(mongoSettings);
10 mongoServer = mongoClient .GetServer();
11 mongoDataBase = mongoServer.GetDatabase(“数据库名称”);
12 mongoCollection = mongoDataBase.GetCollection(tableName);

posted @ 2017-03-24 08:56  法号阿兴  阅读(1811)  评论(0编辑  收藏  举报