Package com.mongodb
Class MongoClientSettings.Builder
- java.lang.Object
-
- com.mongodb.MongoClientSettings.Builder
-
- Enclosing class:
- MongoClientSettings
@NotThreadSafe public static final class MongoClientSettings.Builder extends Object
A builder forMongoClientSettings
so thatMongoClientSettings
can be immutable, and to support easier construction through chaining.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MongoClientSettings.Builder
addCommandListener(CommandListener commandListener)
Adds the given command listener.MongoClientSettings.Builder
applicationName(String applicationName)
Sets the logical name of the application using this MongoClient.MongoClientSettings.Builder
applyConnectionString(ConnectionString connectionString)
Takes the settings from the givenConnectionString
and applies them to the builderMongoClientSettings.Builder
applyToClusterSettings(Block<ClusterSettings.Builder> block)
Applies theClusterSettings.Builder
block and then sets the clusterSettings.MongoClientSettings.Builder
applyToConnectionPoolSettings(Block<ConnectionPoolSettings.Builder> block)
Applies theConnectionPoolSettings.Builder
block and then sets the connectionPoolSettings.MongoClientSettings.Builder
applyToServerSettings(Block<ServerSettings.Builder> block)
Applies theServerSettings.Builder
block and then sets the serverSettings.MongoClientSettings.Builder
applyToSocketSettings(Block<SocketSettings.Builder> block)
Applies theSocketSettings.Builder
block and then sets the socketSettings.MongoClientSettings.Builder
applyToSslSettings(Block<SslSettings.Builder> block)
Applies theSslSettings.Builder
block and then sets the sslSettings.MongoClientSettings.Builder
autoEncryptionSettings(AutoEncryptionSettings autoEncryptionSettings)
Sets the auto-encryption settings A separate, internalMongoClient
is created if any of the following are true:AutoEncryptionSettings.keyVaultClient
is not passedAutoEncryptionSettings.bypassAutomaticEncryption
isfalse
If an internalMongoClient
is created, it is configured with the same options as the parentMongoClient
exceptminPoolSize
is set to0
andAutoEncryptionSettings
is omitted.MongoClientSettings
build()
Build an instance ofMongoClientSettings
.MongoClientSettings.Builder
codecRegistry(CodecRegistry codecRegistry)
Sets the codec registryMongoClientSettings.Builder
commandListenerList(List<CommandListener> commandListeners)
Sets the the command listenersMongoClientSettings.Builder
compressorList(List<MongoCompressor> compressorList)
Sets the compressors to use for compressing messages to the server.MongoClientSettings.Builder
contextProvider(ContextProvider contextProvider)
Sets the context providerMongoClientSettings.Builder
credential(MongoCredential credential)
Sets the credential.MongoClientSettings.Builder
readConcern(ReadConcern readConcern)
Sets the read concern.MongoClientSettings.Builder
readPreference(ReadPreference readPreference)
Sets the read preference.MongoClientSettings.Builder
retryReads(boolean retryReads)
Sets whether reads should be retried if they fail due to a network error.MongoClientSettings.Builder
retryWrites(boolean retryWrites)
Sets whether writes should be retried if they fail due to a network error.MongoClientSettings.Builder
serverApi(ServerApi serverApi)
Sets the server API to use when sending commands to the server.MongoClientSettings.Builder
streamFactoryFactory(StreamFactoryFactory streamFactoryFactory)
Sets the factory to use to create aStreamFactory
.MongoClientSettings.Builder
uuidRepresentation(UuidRepresentation uuidRepresentation)
Sets the UUID representation to use when encoding instances ofUUID
and when decoding BSON binary values with subtype of 3.MongoClientSettings.Builder
writeConcern(WriteConcern writeConcern)
Sets the write concern.
-
-
-
Method Detail
-
applyConnectionString
public MongoClientSettings.Builder applyConnectionString(ConnectionString connectionString)
Takes the settings from the givenConnectionString
and applies them to the builder- Parameters:
connectionString
- the connection string containing details of how to connect to MongoDB- Returns:
- this
-
applyToClusterSettings
public MongoClientSettings.Builder applyToClusterSettings(Block<ClusterSettings.Builder> block)
Applies theClusterSettings.Builder
block and then sets the clusterSettings.- Parameters:
block
- the block to apply to the ClusterSettings.- Returns:
- this
- See Also:
MongoClientSettings.getClusterSettings()
-
applyToSocketSettings
public MongoClientSettings.Builder applyToSocketSettings(Block<SocketSettings.Builder> block)
Applies theSocketSettings.Builder
block and then sets the socketSettings.- Parameters:
block
- the block to apply to the SocketSettings.- Returns:
- this
- See Also:
MongoClientSettings.getSocketSettings()
-
applyToConnectionPoolSettings
public MongoClientSettings.Builder applyToConnectionPoolSettings(Block<ConnectionPoolSettings.Builder> block)
Applies theConnectionPoolSettings.Builder
block and then sets the connectionPoolSettings.- Parameters:
block
- the block to apply to the ConnectionPoolSettings.- Returns:
- this
- See Also:
MongoClientSettings.getConnectionPoolSettings()
-
applyToServerSettings
public MongoClientSettings.Builder applyToServerSettings(Block<ServerSettings.Builder> block)
Applies theServerSettings.Builder
block and then sets the serverSettings.- Parameters:
block
- the block to apply to the ServerSettings.- Returns:
- this
- See Also:
MongoClientSettings.getServerSettings()
-
applyToSslSettings
public MongoClientSettings.Builder applyToSslSettings(Block<SslSettings.Builder> block)
Applies theSslSettings.Builder
block and then sets the sslSettings.- Parameters:
block
- the block to apply to the SslSettings.- Returns:
- this
- See Also:
MongoClientSettings.getSslSettings()
-
readPreference
public MongoClientSettings.Builder readPreference(ReadPreference readPreference)
Sets the read preference.- Parameters:
readPreference
- read preference- Returns:
- this
- See Also:
MongoClientSettings.getReadPreference()
-
writeConcern
public MongoClientSettings.Builder writeConcern(WriteConcern writeConcern)
Sets the write concern.- Parameters:
writeConcern
- the write concern- Returns:
- this
- See Also:
MongoClientSettings.getWriteConcern()
-
retryWrites
public MongoClientSettings.Builder retryWrites(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:
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.- Parameters:
retryReads
- sets if reads should be retried if they fail due to a network error.- Returns:
- this
- Since:
- 3.11
- See Also:
MongoClientSettings.getRetryReads()
- Since server release
- 3.6
-
readConcern
public MongoClientSettings.Builder readConcern(ReadConcern readConcern)
Sets the read concern.- Parameters:
readConcern
- the read concern- Returns:
- this
- MongoDB documentation
- Read Concern
- Since server release
- 3.2
-
credential
public MongoClientSettings.Builder credential(MongoCredential credential)
Sets the credential.- Parameters:
credential
- the credential- Returns:
- this
-
codecRegistry
public MongoClientSettings.Builder codecRegistry(CodecRegistry codecRegistry)
Sets the codec registry- Parameters:
codecRegistry
- the codec registry- Returns:
- this
- See Also:
MongoClientSettings.getCodecRegistry()
-
streamFactoryFactory
public MongoClientSettings.Builder streamFactoryFactory(StreamFactoryFactory streamFactoryFactory)
Sets the factory to use to create aStreamFactory
.- Parameters:
streamFactoryFactory
- the stream factory factory- Returns:
- this
-
addCommandListener
public MongoClientSettings.Builder addCommandListener(CommandListener commandListener)
Adds the given command listener.- Parameters:
commandListener
- the command listener- Returns:
- this
-
commandListenerList
public MongoClientSettings.Builder commandListenerList(List<CommandListener> commandListeners)
Sets the the command listeners- Parameters:
commandListeners
- the list of command listeners- Returns:
- this
-
applicationName
public MongoClientSettings.Builder applicationName(@Nullable 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:
MongoClientSettings.getApplicationName()
- Since server release
- 3.4
-
compressorList
public MongoClientSettings.Builder compressorList(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:
MongoClientSettings.getCompressorList()
- Since server release
- 3.4
-
uuidRepresentation
public MongoClientSettings.Builder uuidRepresentation(UuidRepresentation uuidRepresentation)
Sets the UUID representation to use when encoding instances ofUUID
and when decoding BSON binary values with subtype of 3.See
MongoClientSettings.getUuidRepresentation()
for recommendations on settings this value- Parameters:
uuidRepresentation
- the UUID representation, which may not be null- Returns:
- this
- Since:
- 3.12
-
serverApi
public MongoClientSettings.Builder serverApi(ServerApi serverApi)
Sets the server API to use when sending commands to the server.This is required for some MongoDB deployments.
- Parameters:
serverApi
- the server API, which may not be null- Returns:
- this
- Since:
- 4.3
-
autoEncryptionSettings
public MongoClientSettings.Builder autoEncryptionSettings(@Nullable AutoEncryptionSettings autoEncryptionSettings)
Sets the auto-encryption settings A separate, internalMongoClient
is created if any of the following are true:AutoEncryptionSettings.keyVaultClient
is not passedAutoEncryptionSettings.bypassAutomaticEncryption
isfalse
MongoClient
is created, it is configured with the same options as the parentMongoClient
exceptminPoolSize
is set to0
andAutoEncryptionSettings
is omitted.- Parameters:
autoEncryptionSettings
- the auto-encryption settings- Returns:
- this
- Since:
- 3.11
- See Also:
MongoClientSettings.getAutoEncryptionSettings()
-
contextProvider
public MongoClientSettings.Builder contextProvider(@Nullable ContextProvider contextProvider)
Sets the context providerWhen used with the synchronous driver, this must be an instance of
com.mongodb.client.SynchronousContextProvider
. When used with the reactive streams driver, this must be an instance ofcom.mongodb.reactivestreams.client.ReactiveContextProvider
.- Parameters:
contextProvider
- the context provider- Returns:
- this
- Since:
- 4.4
-
build
public MongoClientSettings build()
Build an instance ofMongoClientSettings
.- Returns:
- the settings from this builder
-
-