Package io.vertx.mongo.client
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 Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Future<java.lang.Void>
close()
Close the client and release its resourcesvoid
close(Handler<AsyncResult<java.lang.Void>> handler)
Close the client and release its resourcesstatic MongoClient
create(Vertx vertx)
Create a Mongo client which maintains its own data source and connects to a default server.static MongoClient
create(Vertx vertx, ClientConfig config)
Create a Mongo client which maintains its own data source.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 sourcestatic 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 nameClusterDescription
getClusterDescription()
Gets the current cluster description.MongoDatabase
getDatabase(java.lang.String name)
Gets the database with the given name.MongoResult<java.lang.String>
listDatabaseNames()
Get a list of the database namesMongoResult<java.lang.String>
listDatabaseNames(ClientSession clientSession)
Get a list of the database namesMongoResult<JsonObject>
listDatabases()
Gets the list of databasesMongoResult<JsonObject>
listDatabases(ClientSession clientSession)
Gets the list of databasesMongoResult<JsonObject>
listDatabases(ClientSession clientSession, ListDatabasesOptions options)
Gets the list of databasesMongoResult<JsonObject>
listDatabases(ListDatabasesOptions options)
Gets the list of databasesFuture<ClientSession>
startSession()
Creates a client session.void
startSession(Handler<AsyncResult<ClientSession>> resultHandler)
Creates a client session.Future<ClientSession>
startSession(ClientSessionOptions options)
Creates a client session.void
startSession(ClientSessionOptions options, Handler<AsyncResult<ClientSession>> resultHandler)
Creates a client session.MongoResult<ChangeStreamDocument<JsonObject>>
watch()
Creates a change stream for this client.MongoResult<ChangeStreamDocument<JsonObject>>
watch(JsonArray pipeline)
Creates a change stream for this client.MongoResult<ChangeStreamDocument<JsonObject>>
watch(JsonArray pipeline, ChangeStreamOptions options)
Creates a change stream for this client.MongoResult<ChangeStreamDocument<JsonObject>>
watch(ChangeStreamOptions options)
Creates a change stream for this client.MongoResult<ChangeStreamDocument<JsonObject>>
watch(ClientSession clientSession)
Creates a change stream for this client.MongoResult<ChangeStreamDocument<JsonObject>>
watch(ClientSession clientSession, JsonArray pipeline)
Creates a change stream for this client.MongoResult<ChangeStreamDocument<JsonObject>>
watch(ClientSession clientSession, JsonArray pipeline, ChangeStreamOptions options)
Creates a change stream for this client.MongoResult<ChangeStreamDocument<JsonObject>>
watch(ClientSession clientSession, ChangeStreamOptions options)
Creates a change stream for this client.
-
-
-
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 instanceconfig
- 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 instanceconfig
- the configurationdataSourceName
- 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 instanceconfig
- 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(ListDatabasesOptions options)
Gets the list of databases- Parameters:
options
- options- 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 operationoptions
- options- Returns:
- the fluent list databases interface
- Since:
- 1.7
- Since server release
- 3.6
-
watch
MongoResult<ChangeStreamDocument<JsonObject>> watch()
Creates a change stream for this client.- Returns:
- the change stream read stream
- Since:
- 1.9
- Since server release
- 4.0
- MongoDB documentation
- Change Streams
-
watch
MongoResult<ChangeStreamDocument<JsonObject>> watch(ChangeStreamOptions options)
Creates a change stream for this client.- Parameters:
options
- options- Returns:
- the change stream read stream
- Since:
- 1.9
- Since server release
- 4.0
- MongoDB documentation
- Change Streams
-
watch
MongoResult<ChangeStreamDocument<JsonObject>> watch(JsonArray pipeline)
Creates a change stream for this client.- Parameters:
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
-
watch
MongoResult<ChangeStreamDocument<JsonObject>> watch(JsonArray pipeline, ChangeStreamOptions options)
Creates a change stream for this client.- Parameters:
pipeline
- the aggregation pipeline to apply to the change stream.options
- options- Returns:
- the change stream read stream
- Since:
- 1.9
- Since server release
- 4.0
- MongoDB documentation
- Change Streams
-
watch
MongoResult<ChangeStreamDocument<JsonObject>> watch(ClientSession clientSession)
Creates a change stream for this client.- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- the change stream read stream
- Since:
- 1.9
- Since server release
- 4.0
- MongoDB documentation
- Change Streams
-
watch
MongoResult<ChangeStreamDocument<JsonObject>> watch(ClientSession clientSession, ChangeStreamOptions options)
Creates a change stream for this client.- Parameters:
clientSession
- the client session with which to associate this operationoptions
- options- Returns:
- the change stream read stream
- Since:
- 1.9
- Since server release
- 4.0
- MongoDB documentation
- Change Streams
-
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 operationpipeline
- 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
-
watch
MongoResult<ChangeStreamDocument<JsonObject>> watch(ClientSession clientSession, JsonArray pipeline, ChangeStreamOptions options)
Creates a change stream for this client.- Parameters:
clientSession
- the client session with which to associate this operationpipeline
- the aggregation pipeline to apply to the change stream.options
- options- 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 sessionresultHandler
- an async result for the client session.- Since:
- 1.7
- Since server release
- 3.6
-
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:
- 4.1
- See Also:
ClusterSettings.Builder.addClusterListener(ClusterListener)
,MongoClientSettings.Builder.applyToClusterSettings(com.mongodb.Block)
-
-