AutoCloseable, Closeable@Immutable public interface MongoClient extends Closeable
Instance of this class serve as factories for MongoDatabase instances.
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Close the client, which will close all underlying cached resources, including, for example,
sockets and background monitoring threads.
|
MongoDatabase |
getDatabase(String name) |
Gets the database with the given name.
|
MongoClientSettings |
getSettings() |
Deprecated.
this method is being removed
|
MongoIterable<String> |
listDatabaseNames() |
Get a list of the database names
|
MongoIterable<String> |
listDatabaseNames(ClientSession clientSession) |
Get a list of the database names
|
ListDatabasesIterable<Document> |
listDatabases() |
Gets the list of databases
|
ListDatabasesIterable<Document> |
listDatabases(ClientSession clientSession) |
Gets the list of databases
|
<TResult> ListDatabasesIterable<TResult> |
listDatabases(ClientSession clientSession,
Class<TResult> resultClass) |
Gets the list of databases
|
<TResult> ListDatabasesIterable<TResult> |
listDatabases(Class<TResult> resultClass) |
Gets the list of databases
|
void |
startSession(SingleResultCallback<ClientSession> callback) |
Creates a client session with default options.
|
void |
startSession(ClientSessionOptions options,
SingleResultCallback<ClientSession> callback) |
Creates a client session.
|
ChangeStreamIterable<Document> |
watch() |
Creates a change stream for this client.
|
ChangeStreamIterable<Document> |
watch(ClientSession clientSession) |
Creates a change stream for this client.
|
<TResult> ChangeStreamIterable<TResult> |
watch(ClientSession clientSession,
Class<TResult> resultClass) |
Creates a change stream for this client.
|
ChangeStreamIterable<Document> |
watch(ClientSession clientSession,
List<? extends Bson> pipeline) |
Creates a change stream for this client.
|
<TResult> ChangeStreamIterable<TResult> |
watch(ClientSession clientSession,
List<? extends Bson> pipeline,
Class<TResult> resultClass) |
Creates a change stream for this client.
|
<TResult> ChangeStreamIterable<TResult> |
watch(Class<TResult> resultClass) |
Creates a change stream for this client.
|
ChangeStreamIterable<Document> |
watch(List<? extends Bson> pipeline) |
Creates a change stream for this client.
|
<TResult> ChangeStreamIterable<TResult> |
watch(List<? extends Bson> pipeline,
Class<TResult> resultClass) |
Creates a change stream for this client.
|
void startSession(SingleResultCallback<ClientSession> callback)
Note: A ClientSession instance can not be used concurrently in multiple asynchronous operations.
callback - the callback that is passed the clientSession or a MongoClientException if the MongoDB cluster to which
this client is connected does not support sessionsvoid startSession(ClientSessionOptions options, SingleResultCallback<ClientSession> callback)
Note: A ClientSession instance can not be used concurrently in multiple asynchronous operations.
options - the options for the client sessioncallback - the callback that is passed the clientSession or a MongoClientException if the MongoDB cluster to which
this client is connected does not support sessionsMongoDatabase getDatabase(String name)
name - the name of the databaseIllegalArgumentException - if databaseName is invalidMongoNamespace.checkDatabaseNameValidity(String)void close()
close in interface AutoCloseableclose in interface Closeable@Deprecated MongoClientSettings getSettings()
Note: MongoClientSettings is immutable.
MongoIterable<String> listDatabaseNames()
MongoIterable<String> listDatabaseNames(ClientSession clientSession)
clientSession - the client session with which to associate this operationListDatabasesIterable<Document> listDatabases()
ListDatabasesIterable<Document> listDatabases(ClientSession clientSession)
clientSession - the client session with which to associate this operation<TResult> ListDatabasesIterable<TResult> listDatabases(Class<TResult> resultClass)
TResult - the type of the class to use instead of Document.resultClass - the class to cast the database documents to<TResult> ListDatabasesIterable<TResult> listDatabases(ClientSession clientSession, Class<TResult> resultClass)
TResult - the type of the class to use instead of Document.clientSession - the client session with which to associate this operationresultClass - the class to cast the database documents toChangeStreamIterable<Document> watch()
<TResult> ChangeStreamIterable<TResult> watch(Class<TResult> resultClass)
TResult - the target document type of the iterable.resultClass - the class to decode each document intoChangeStreamIterable<Document> watch(List<? extends Bson> pipeline)
pipeline - the aggregation pipeline to apply to the change stream.<TResult> ChangeStreamIterable<TResult> watch(List<? extends Bson> pipeline, Class<TResult> resultClass)
TResult - the target document type of the iterable.pipeline - the aggregation pipeline to apply to the change streamresultClass - the class to decode each document intoChangeStreamIterable<Document> watch(ClientSession clientSession)
clientSession - the client session with which to associate this operation<TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, Class<TResult> resultClass)
TResult - the target document type of the iterable.clientSession - the client session with which to associate this operationresultClass - the class to decode each document intoChangeStreamIterable<Document> watch(ClientSession clientSession, List<? extends Bson> pipeline)
clientSession - the client session with which to associate this operationpipeline - the aggregation pipeline to apply to the change stream.<TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass)
TResult - the target document type of the iterable.clientSession - the client session with which to associate this operationpipeline - the aggregation pipeline to apply to the change streamresultClass - the class to decode each document into