Interface MongoClient

All Superinterfaces:
AutoCloseable, Closeable, MongoCluster

@Immutable public interface MongoClient extends MongoCluster, Closeable
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 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 interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getClusterDescription

      com.mongodb.connection.ClusterDescription getClusterDescription()
      Gets the current cluster description.

      This method will not block, meaning that it may return a ClusterDescription whose clusterType is unknown and whose ServerDescriptions 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 a ClusterListener via the ClusterSettings in MongoClientSettings.

      Returns:
      the current cluster description
      Since:
      3.11
      See Also:
      • ClusterSettings.Builder.addClusterListener(ClusterListener)
      • MongoClientSettings.Builder.applyToClusterSettings(com.mongodb.Block)