Class MongoClientSettings


  • public class MongoClientSettings
    extends java.lang.Object
    • Constructor Detail

      • MongoClientSettings

        public MongoClientSettings()
      • MongoClientSettings

        public MongoClientSettings​(JsonObject json)
    • Method Detail

      • getClusterSettings

        public ClusterSettings getClusterSettings()
        Gets the cluster settings.
        Returns:
        the cluster settings
      • getSocketSettings

        public SocketSettings getSocketSettings()
        Gets the connection-specific settings wrapped in a settings object. This settings object uses the values for connectTimeout, socketTimeout and socketKeepAlive.
        Returns:
        a SocketSettings object populated with the connection settings from this MongoClientSettings instance.
        See Also:
        SocketSettings
      • getConnectionPoolSettings

        public ConnectionPoolSettings getConnectionPoolSettings()
        Gets the settings for the connection provider in a settings object. This settings object wraps the values for minConnectionPoolSize, maxConnectionPoolSize, maxWaitTime, maxConnectionIdleTime and maxConnectionLifeTime.
        Returns:
        a ConnectionPoolSettings populated with the settings from this MongoClientSettings instance that relate to the connection provider.
        See Also:
        ConnectionPoolSettings
      • getServerSettings

        public ServerSettings getServerSettings()
        Gets the server-specific settings wrapped in a settings object. This settings object uses the heartbeatFrequency and minHeartbeatFrequency values from this MongoClientSettings instance.
        Returns:
        a ServerSettings
        See Also:
        ServerSettings
      • getSslSettings

        public SslSettings getSslSettings()
        Gets the SSL settings.
        Returns:
        the SSL settings
      • getReadPreference

        public ReadPreference getReadPreference()
        The read preference to use for queries, map-reduce, aggregation, and count.

        Default is ReadPreference.primary().

        Returns:
        the read preference
        See Also:
        ReadPreference.primary()
      • setRetryWrites

        public MongoClientSettings setRetryWrites​(java.lang.Boolean retryWrites)
        Sets whether writes should be retried if they fail due to a network 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.
        Returns:
        this
        See Also:
        isRetryWrites()
        Since server release
        3.6
      • isRetryWrites

        public java.lang.Boolean isRetryWrites()
        Returns true if 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

        Returns:
        the retryWrites value
        Since server release
        3.6
      • setRetryReads

        public MongoClientSettings setRetryReads​(java.lang.Boolean retryReads)
        Sets whether reads should be retried if they fail due to a network error.
        Parameters:
        retryReads - sets if reads should be retried if they fail due to a network error.
        Returns:
        this
        Since:
        3.11
        See Also:
        isRetryReads()
        Since server release
        3.6
      • isRetryReads

        public java.lang.Boolean isRetryReads()
        Returns true if reads should be retried if they fail due to a network error or other retryable error. The default value is true.
        Returns:
        the retryReads value
        Since:
        3.11
        Since server release
        3.6
      • setReadConcern

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

        public ReadConcern getReadConcern()
        The read concern to use.
        Returns:
        the read concern
        Since server release
        3.2
        MongoDB documentation
        Read Concern
      • getCredential

        public MongoCredential getCredential()
        Gets the credential.
        Returns:
        the credential, which may be null
      • setApplicationName

        public MongoClientSettings setApplicationName​(java.lang.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
        See Also:
        getApplicationName()
        Since server release
        3.4
      • getApplicationName

        public java.lang.String getApplicationName()
        Gets 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.

        Default is null.

        Returns:
        the application name, which may be null
        Since server release
        3.4
      • setCompressorList

        public MongoClientSettings setCompressorList​(java.util.List<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
        See Also:
        getCompressorList()
        Since server release
        3.4
      • getCompressorList

        public java.util.List<MongoCompressor> getCompressorList()
      • getAutoEncryptionSettings

        public AutoEncryptionSettings getAutoEncryptionSettings()
        Gets the auto-encryption settings.

        Client side encryption enables an application to specify what fields in a collection must be encrypted, and the driver automatically encrypts commands and decrypts results.

        Automatic encryption is an enterprise only feature that only applies to operations on a collection. Automatic encryption is not supported for operations on a database or view and will result in error. To bypass automatic encryption, set bypassAutoEncryption=true in ClientSideEncryptionOptions.

        Explicit encryption/decryption and automatic decryption is a community feature, enabled with the new com.mongodb.client.vault .ClientEncryption type. A MongoClient configured with bypassAutoEncryption=true will still automatically decrypt.

        Automatic encryption requires the authenticated user to have the listCollections privilege action.

        Note: support for client side encryption is in beta. Backwards-breaking changes may be made before the final release.

        Returns:
        the auto-encryption settings, which may be null
        Since:
        3.11