Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Interface MongoClient

  • All Superinterfaces:
    AutoCloseable, Closeable


    @Immutable
    public interface MongoClient
    extends 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.

    Instance of this class serve as factories for MongoDatabase instances.

    Since:
    3.0
    • Method Detail

      • startSession

        void startSession​(ClientSessionOptions options,
                          SingleResultCallback<ClientSession> callback)
        Creates a client session.

        Note: A ClientSession instance can not be used concurrently in multiple asynchronous operations.

        Parameters:
        options - the options for the client session
        callback - the callback that is passed the clientSession or a MongoClientException if the MongoDB cluster to which this client is connected does not support sessions
        Since:
        3.6
        Since server release
        3.6
      • 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
      • listDatabaseNames

        MongoIterable<String> listDatabaseNames​()
        Get a list of the database names
        Returns:
        an iterable containing all the names of all the databases
        MongoDB documentation
        List Databases
      • listDatabaseNames

        MongoIterable<String> listDatabaseNames​(ClientSession clientSession)
        Get a list of the database names
        Parameters:
        clientSession - the client session with which to associate this operation
        Returns:
        an iterable containing all the names of all the databases
        Since:
        3.6
        MongoDB documentation
        List Databases
        Since server release
        3.6
      • listDatabases

        ListDatabasesIterable<Document> listDatabases​(ClientSession clientSession)
        Gets the list of databases
        Parameters:
        clientSession - the client session with which to associate this operation
        Returns:
        the list databases iterable interface
        Since:
        3.6
        MongoDB documentation
        List Databases
        Since server release
        3.6
      • listDatabases

        <TResult> ListDatabasesIterable<TResult> listDatabases​(Class<TResult> resultClass)
        Gets the list of databases
        Type Parameters:
        TResult - the type of the class to use instead of Document.
        Parameters:
        resultClass - the class to cast the database documents to
        Returns:
        the list databases iterable interface
      • listDatabases

        <TResult> ListDatabasesIterable<TResult> listDatabases​(ClientSession clientSession,
                                                               Class<TResult> resultClass)
        Gets the list of databases
        Type Parameters:
        TResult - the type of the class to use instead of Document.
        Parameters:
        clientSession - the client session with which to associate this operation
        resultClass - the class to cast the database documents to
        Returns:
        the list databases iterable interface
        Since:
        3.6
        MongoDB documentation
        List Databases
        Since server release
        3.6