Interface MongoClient

  • All Superinterfaces:
    Closeable

    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 server as factories for MongoDatabase instances.

    Since:
    1.0
    • Method Detail

      • create

        static MongoClient create​(Vertx vertx)
        Create a Mongo client which maintains its own data source and connects to a default server.
        Parameters:
        vertx - the Vert.x instance
        Returns:
        the client
      • create

        static MongoClient create​(Vertx vertx,
                                  ClientConfig config)
        Create a Mongo client which maintains its own data source.
        Parameters:
        vertx - the Vert.x instance
        config - the configuration
        Returns:
        the client
      • createShared

        static MongoClient createShared​(Vertx vertx,
                                        ClientConfig config,
                                        java.lang.String dataSourceName)
        Create a Mongo client which shares its data source with any other Mongo clients created with the same data source name
        Parameters:
        vertx - the Vert.x instance
        config - the configuration
        dataSourceName - the data source name
        Returns:
        the client
      • createShared

        static MongoClient createShared​(Vertx vertx,
                                        ClientConfig config)
        Create a Mongo client which shares its data source with any other Mongo clients created with the same default data source
        Parameters:
        vertx - the Vert.x instance
        config - the configuration
        Returns:
        the client
      • close

        Future<java.lang.Void> close()
        Close the client and release its resources
      • close

        void close​(Handler<AsyncResult<java.lang.Void>> handler)
        Close the client and release its resources
        Parameters:
        handler - handler
      • getDatabase

        MongoDatabase getDatabase​(java.lang.String name)
        Gets the database with the given name.
        Parameters:
        name - the name of the database
        Returns:
        the database
      • listDatabaseNames

        MongoResult<java.lang.String> listDatabaseNames()
        Get a list of the database names
        Returns:
        an result containing all the names of all the databases
        MongoDB documentation
        List Databases
      • listDatabaseNames

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

        MongoResult<JsonObject> listDatabases()
        Gets the list of databases
        Returns:
        the fluent list databases interface
      • listDatabases

        MongoResult<JsonObject> listDatabases​(ClientSession clientSession)
        Gets the list of databases
        Parameters:
        clientSession - the client session with which to associate this operation
        Returns:
        the fluent list databases interface
        Since:
        1.7
        Since server release
        3.6
      • listDatabases

        MongoResult<JsonObject> listDatabases​(ClientSession clientSession,
                                              ListDatabasesOptions options)
        Gets the list of databases
        Parameters:
        clientSession - the client session with which to associate this operation
        options - options
        Returns:
        the fluent list databases interface
        Since:
        1.7
        Since server release
        3.6
      • watch

        MongoResult<ChangeStreamDocument<JsonObject>> watch​(ClientSession clientSession,
                                                            JsonArray pipeline)
        Creates a change stream for this client.
        Parameters:
        clientSession - the client session with which to associate this operation
        pipeline - the aggregation pipeline to apply to the change stream.
        Returns:
        the change stream read stream
        Since:
        1.9
        Since server release
        4.0
        MongoDB documentation
        Change Streams
      • startSession

        Future<ClientSession> startSession()
        Creates a client session.
        Returns:
        a future for the client session.
        Since:
        1.9
        Since server release
        3.6
      • startSession

        void startSession​(Handler<AsyncResult<ClientSession>> resultHandler)
        Creates a client session.
        Parameters:
        resultHandler - an async result for the client session.
        Since:
        1.9
        Since server release
        3.6
      • startSession

        Future<ClientSession> startSession​(ClientSessionOptions options)
        Creates a client session.
        Parameters:
        options - the options for the client session
        Returns:
        a future for the client session.
        Since:
        1.7
        Since server release
        3.6
      • startSession

        void startSession​(ClientSessionOptions options,
                          Handler<AsyncResult<ClientSession>> resultHandler)
        Creates a client session.
        Parameters:
        options - the options for the client session
        resultHandler - an async result for the client session.
        Since:
        1.7
        Since server release
        3.6