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