Package com.mongodb.client
Interface MongoClient
- All Superinterfaces:
AutoCloseable
,Closeable
,MongoCluster
A client-side representation of a MongoDB cluster. Instances can represent either a standalone MongoDB instance, a replica set,
or a sharded cluster. Instance of this class are responsible for maintaining an up-to-date state of the cluster,
and possibly cache resources related to this, including background threads for monitoring, and connection pools.
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
close()
Close the client, which will close all underlying cached resources, including, for example, sockets and background monitoring threads.Gets the current cluster description.Methods inherited from interface com.mongodb.client.MongoCluster
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
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:
-