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);