Class MongoClientSettings.Builder

  • Enclosing class:
    MongoClientSettings

    @NotThreadSafe
    public static final class MongoClientSettings.Builder
    extends Object
    A builder for MongoClientSettings so that MongoClientSettings can be immutable, and to support easier construction through chaining.
    • Method Detail

      • applyConnectionString

        public MongoClientSettings.Builder applyConnectionString​(com.mongodb.ConnectionString connectionString)
        Takes the settings from the given ConnectionString and applies them to the builder
        Parameters:
        connectionString - the connection string containing details of how to connect to MongoDB
        Returns:
        this
        Since:
        3.7
      • applyToClusterSettings

        public MongoClientSettings.Builder applyToClusterSettings​(com.mongodb.Block<com.mongodb.connection.ClusterSettings.Builder> block)
        Applies the ClusterSettings.Builder block and then sets the clusterSettings.
        Parameters:
        block - the block to apply to the ClusterSettings.
        Returns:
        this
        Since:
        3.7
        See Also:
        MongoClientSettings.getClusterSettings()
      • applyToSocketSettings

        public MongoClientSettings.Builder applyToSocketSettings​(com.mongodb.Block<com.mongodb.connection.SocketSettings.Builder> block)
        Applies the SocketSettings.Builder block and then sets the socketSettings.
        Parameters:
        block - the block to apply to the SocketSettings.
        Returns:
        this
        Since:
        3.7
        See Also:
        MongoClientSettings.getSocketSettings()
      • applyToConnectionPoolSettings

        public MongoClientSettings.Builder applyToConnectionPoolSettings​(com.mongodb.Block<com.mongodb.connection.ConnectionPoolSettings.Builder> block)
        Applies the ConnectionPoolSettings.Builder block and then sets the connectionPoolSettings.
        Parameters:
        block - the block to apply to the ConnectionPoolSettings.
        Returns:
        this
        Since:
        3.7
        See Also:
        MongoClientSettings.getConnectionPoolSettings()
      • applyToServerSettings

        public MongoClientSettings.Builder applyToServerSettings​(com.mongodb.Block<com.mongodb.connection.ServerSettings.Builder> block)
        Applies the ServerSettings.Builder block and then sets the serverSettings.
        Parameters:
        block - the block to apply to the ServerSettings.
        Returns:
        this
        Since:
        3.7
        See Also:
        MongoClientSettings.getServerSettings()
      • applyToSslSettings

        public MongoClientSettings.Builder applyToSslSettings​(com.mongodb.Block<com.mongodb.connection.SslSettings.Builder> block)
        Applies the SslSettings.Builder block and then sets the sslSettings.
        Parameters:
        block - the block to apply to the SslSettings.
        Returns:
        this
        Since:
        3.7
        See Also:
        MongoClientSettings.getSslSettings()
      • retryWrites

        public MongoClientSettings.Builder retryWrites​(boolean retryWrites)
        Sets whether writes should be retried if they fail due to a network error or other retryable error.

        Starting with the 3.11.0 release, the default value is true

        Parameters:
        retryWrites - sets if writes should be retried if they fail due to a network error or other retryable error.
        Returns:
        this
        Since:
        3.6
        See Also:
        MongoClientSettings.getRetryWrites()
        Since server release
        3.6
      • retryReads

        public MongoClientSettings.Builder retryReads​(boolean retryReads)
        Sets whether reads should be retried if they fail due to a network error or other retryable error.
        Parameters:
        retryReads - sets if reads should be retried if they fail due to a network error or other retryable error.
        Returns:
        this
        Since:
        3.11
        See Also:
        MongoClientSettings.getRetryReads()
        Since server release
        3.6
      • readConcern

        public MongoClientSettings.Builder readConcern​(com.mongodb.ReadConcern readConcern)
        Sets the read concern.
        Parameters:
        readConcern - the read concern
        Returns:
        this
        Since:
        3.2
        MongoDB documentation
        Read Concern
        Since server release
        3.2
      • streamFactoryFactory

        public MongoClientSettings.Builder streamFactoryFactory​(com.mongodb.connection.StreamFactoryFactory streamFactoryFactory)
        Sets the factory to use to create a StreamFactory.
        Parameters:
        streamFactoryFactory - the stream factory factory
        Returns:
        this
        Since:
        3.1
      • addCommandListener

        public MongoClientSettings.Builder addCommandListener​(com.mongodb.event.CommandListener commandListener)
        Adds the given command listener.
        Parameters:
        commandListener - the command listener
        Returns:
        this
        Since:
        3.3
      • applicationName

        public MongoClientSettings.Builder applicationName​(String applicationName)
        Sets the logical name of the application using this MongoClient. The application name may be used by the client to identify the application to the server, for use in server logs, slow query logs, and profile collection.
        Parameters:
        applicationName - the logical name of the application using this MongoClient. It may be null. The UTF-8 encoding may not exceed 128 bytes.
        Returns:
        this
        Since:
        3.4
        See Also:
        MongoClientSettings.getApplicationName()
        Since server release
        3.4
      • compressorList

        public MongoClientSettings.Builder compressorList​(List<com.mongodb.MongoCompressor> compressorList)
        Sets the compressors to use for compressing messages to the server. The driver will use the first compressor in the list that the server is configured to support.
        Parameters:
        compressorList - the list of compressors to request
        Returns:
        this
        Since:
        3.6
        See Also:
        ()
        Since server release
        3.4
      • build

        public MongoClientSettings build()
        Build an instance of MongoClientSettings.
        Returns:
        the settings from this builder