/// <summary> /// 构造函数 /// </summary> /// <param name="host">MongoDB 数据库连接主机地址</param> /// <param name="port">MongoDB 数据库连接端口号</param> /// <param name="timeout">MongoDB 数据库连接超时时间</param> /// <param name="dbName">MongoDB 数据库名称</param> /// <returns>MongoDatabase 实例对象</returns> public MongoDBHandler(string host, int port, int timeout, string dbName) { this.MongoConnectionHost = host; this.MongoConnectionPort = port; this.MongoConnectionTimeout = timeout; this.MongoDatabaseName = dbName; MongoClientSettings mongoSetting = new MongoClientSettings(); mongoSetting.ConnectTimeout = new TimeSpan(this.MongoConnectionTimeout * TimeSpan.TicksPerSecond); mongoSetting.Server = new MongoServerAddress(this.MongoConnectionHost, this.MongoConnectionPort); this.FClient = new MongoClient(mongoSetting); this.FDatabase = FClient.GetServer().GetDatabase(dbName); }