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 TypeMethodDescriptionvoidappendMetadata(com.mongodb.MongoDriverInformation mongoDriverInformation) Appends the providedMongoDriverInformationto the existing metadata.voidclose()Close the client, which will close all underlying cached resources, including, for example, sockets and background monitoring threads.com.mongodb.connection.ClusterDescriptionGets 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getClusterDescription
com.mongodb.connection.ClusterDescription getClusterDescription()Gets the current cluster description.This method will not block, meaning that it may return a
ClusterDescriptionwhoseclusterTypeis unknown and whoseServerDescriptions 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 aClusterListenervia theClusterSettingsinMongoClientSettings.- 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 providedMongoDriverInformationto 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
-