@Immutable public interface MongoClient
Instances of this class serve as factories for MongoDatabase
instances.
Instances of this class can be created via the MongoClients
factory.
MongoClients
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the client, which will close all underlying cached resources, including, for example,
sockets and background monitoring threads.
|
MongoDatabase |
getDatabase(java.lang.String databaseName)
Gets a
MongoDatabase instance for the given database name. |
MongoIterable<java.lang.String> |
listDatabaseNames()
Get a list of the database names
|
MongoIterable<java.lang.String> |
listDatabaseNames(ClientSession clientSession)
Get a list of the database names
|
ListDatabasesIterable<Document> |
listDatabases()
Gets the list of databases
|
<TResult> ListDatabasesIterable<TResult> |
listDatabases(java.lang.Class<TResult> resultClass)
Gets the list of databases
|
ListDatabasesIterable<Document> |
listDatabases(ClientSession clientSession)
Gets the list of databases
|
<TResult> ListDatabasesIterable<TResult> |
listDatabases(ClientSession clientSession,
java.lang.Class<TResult> resultClass)
Gets the list of databases
|
ClientSession |
startSession()
Creates a client session with default options.
|
ClientSession |
startSession(ClientSessionOptions options)
Creates a client session.
|
ChangeStreamIterable<Document> |
watch()
Creates a change stream for this client.
|
<TResult> ChangeStreamIterable<TResult> |
watch(java.lang.Class<TResult> resultClass)
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,
java.lang.Class<TResult> resultClass)
Creates a change stream for this client.
|
ChangeStreamIterable<Document> |
watch(ClientSession clientSession,
java.util.List<? extends Bson> pipeline)
Creates a change stream for this client.
|
<TResult> ChangeStreamIterable<TResult> |
watch(ClientSession clientSession,
java.util.List<? extends Bson> pipeline,
java.lang.Class<TResult> resultClass)
Creates a change stream for this client.
|
ChangeStreamIterable<Document> |
watch(java.util.List<? extends Bson> pipeline)
Creates a change stream for this client.
|
<TResult> ChangeStreamIterable<TResult> |
watch(java.util.List<? extends Bson> pipeline,
java.lang.Class<TResult> resultClass)
Creates a change stream for this client.
|
MongoDatabase getDatabase(java.lang.String databaseName)
MongoDatabase
instance for the given database name.databaseName
- the name of the database to retrieveMongoDatabase
representing the specified databasejava.lang.IllegalArgumentException
- if databaseName is invalidMongoNamespace.checkDatabaseNameValidity(String)
ClientSession startSession()
Note: A ClientSession instance can not be used concurrently in multiple operations.
ClientSession startSession(ClientSessionOptions options)
Note: A ClientSession instance can not be used concurrently in multiple operations.
options
- the options for the client sessionvoid close()
MongoIterable<java.lang.String> listDatabaseNames()
MongoIterable<java.lang.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(java.lang.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, java.lang.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(java.lang.Class<TResult> resultClass)
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intoChangeStreamIterable<Document> watch(java.util.List<? extends Bson> pipeline)
pipeline
- the aggregation pipeline to apply to the change stream.<TResult> ChangeStreamIterable<TResult> watch(java.util.List<? extends Bson> pipeline, java.lang.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, java.lang.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, java.util.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, java.util.List<? extends Bson> pipeline, java.lang.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 intoCopyright © 2010 - 2020 Adobe. All Rights Reserved