Interface MongoClient
- All Superinterfaces:
AutoCloseable
,Closeable
,MongoCluster
Instances of this class serve as factories for MongoDatabase
instances.
Instances of this class can be created via the MongoClients
factory.
- Since:
- 3.7
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
appendMetadata
(com.mongodb.MongoDriverInformation mongoDriverInformation) Appends the providedMongoDriverInformation
to the existing metadata.void
close()
Close the client, which will close all underlying cached resources, including, for example, sockets and background monitoring threads.com.mongodb.connection.ClusterDescription
Gets the current cluster description.Methods inherited from interface com.mongodb.client.MongoCluster
bulkWrite, bulkWrite, bulkWrite, bulkWrite, getCodecRegistry, getDatabase, getReadConcern, getReadPreference, getTimeout, getWriteConcern, listDatabaseNames, listDatabaseNames, listDatabases, listDatabases, listDatabases, listDatabases, startSession, startSession, watch, watch, watch, watch, watch, watch, watch, watch, withCodecRegistry, withReadConcern, withReadPreference, withTimeout, withWriteConcern
-
Method Details
-
close
void close()Close the client, which will close all underlying cached resources, including, for example, sockets and background monitoring threads.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getClusterDescription
com.mongodb.connection.ClusterDescription getClusterDescription()Gets the current cluster description.This method will not block, meaning that it may return a
ClusterDescription
whoseclusterType
is unknown and whoseServerDescription
s are all in the connecting state. If the application requires notifications after the driver has connected to a member of the cluster, it should register aClusterListener
via theClusterSettings
inMongoClientSettings
.- Returns:
- the current cluster description
- Since:
- 3.11
- See Also:
-
ClusterSettings.Builder.addClusterListener(ClusterListener)
MongoClientSettings.Builder.applyToClusterSettings(com.mongodb.Block)
-
appendMetadata
void appendMetadata(com.mongodb.MongoDriverInformation mongoDriverInformation) Appends the providedMongoDriverInformation
to the existing metadata.This enables frameworks and libraries to include identifying metadata (e.g., name, version, platform) which might be visible in the MongoD/MongoS logs. This can assist with diagnostics by making client identity visible to the server.
Note: Metadata is limited to 512 bytes; any excess will be truncated.
- Parameters:
mongoDriverInformation
- the driver information to append to the existing metadata- Since:
- 5.6
-