protected virtual bool TryConfigureClientOption(MongoClientSettings settings, BsonElement option) { switch (option.Name) { case "readConcernLevel": var level = (ReadConcernLevel)Enum.Parse(typeof(ReadConcernLevel), option.Value.AsString, ignoreCase: true); settings.ReadConcern = new ReadConcern(level); break; case "readPreference": settings.ReadPreference = ReadPreferenceFromBsonValue(option.Value); break; case "retryWrites": settings.RetryWrites = option.Value.ToBoolean(); break; case "w": if (option.Value.IsString) { settings.WriteConcern = new WriteConcern(option.Value.AsString); } else { settings.WriteConcern = new WriteConcern(option.Value.ToInt32()); } break; case "retryReads": settings.RetryReads = option.Value.ToBoolean(); break; case "appname": settings.ApplicationName = $"{option.Value}_async_{_async}"; break; case "connectTimeoutMS": var connectTimeoutMS = option.Value.ToInt32(); settings.ConnectTimeout = connectTimeoutMS == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromMilliseconds(connectTimeoutMS); break; case "directConnection": var isDirectConnection = option.Value.ToBoolean(); #pragma warning disable CS0618 // Type or member is obsolete settings.ConnectionMode = ConnectionMode.Automatic; settings._connectionModeSwitch(ConnectionModeSwitch.UseDirectConnection); #pragma warning restore CS0618 // Type or member is obsolete settings.DirectConnection = isDirectConnection; if (isDirectConnection) { settings.Servers = new MongoServerAddress[] { settings.Servers.First() }; } break; case "heartbeatFrequencyMS": settings.HeartbeatInterval = TimeSpan.FromMilliseconds(option.Value.ToInt32()); break; case "maxPoolSize": settings.MaxConnectionPoolSize = option.Value.ToInt32(); break; case "minPoolSize": settings.MinConnectionPoolSize = option.Value.ToInt32(); break; case "serverSelectionTimeoutMS": settings.ServerSelectionTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32()); break; case "socketTimeoutMS": settings.SocketTimeout = TimeSpan.FromMilliseconds(option.Value.ToInt32()); break; default: return(false); } return(true); }