在C#中mongohelper的初始化

MongoClientSettings mongoSettings = new MongoClientSettings();
TimeSpan t = new TimeSpan(100);
mongoSettings.ConnectTimeout = t;//设置连接超时时长
mongoSettings.MaxConnectionPoolSize = 2000;//设置连接池最大连接数
MongoCredential cr = MongoCredential.CreateMongoCRCredential("数据库名", "用户名", "密码");//添加用户名、密码
List<MongoCredential> credentials = new List<MongoCredential>();
credentials.Add(cr);
mongoSettings.Credentials = credentials;
mongoSettings.Server =new MongoServerAddress("192.168.1.1",27017);//服务器地址
mongoSettings.ReadPreference = new ReadPreference(ReadPreferenceMode.Primary);
mongoClient = new MongoClient(mongoSettings);
mongoServer = mongoClient .GetServer();
mongoDataBase = mongoServer.GetDatabase(ConfigurationManager.ConnectionStrings[connectionString].ConnectionString.Split(‘|‘)[1]);
mongoCollection = mongoDataBase.GetCollection(tableName);

在C#中mongohelper的初始化

上一篇:RDIFramework.NET开发实例━表约束条件权限的使用-WinForm


下一篇:运用CodeSmith Studio实现C#项目构架