Interface MongoCluster
- All Known Subinterfaces:
MongoClient
The originating MongoClient
is responsible for the closing of resources.
If the originator MongoClient
is closed, then any cluster operations will fail.
- Since:
- 5.2
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGet the codec registry for the MongoCluster.getDatabase
(String databaseName) Gets aMongoDatabase
instance for the given database name.Get the read concern for the MongoCluster.Get the read preference for the MongoCluster.getTimeout
(TimeUnit timeUnit) The time limit for the full execution of an operation.Get the write concern for the MongoCluster.Get a list of the database nameslistDatabaseNames
(ClientSession clientSession) Get a list of the database namesGets the list of databaseslistDatabases
(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 databasesCreates a client session with default options.startSession
(ClientSessionOptions options) Creates a client session.watch()
Creates a change stream for this client.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.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>
Creates a change stream for this client.Creates a change stream for this client.<TResult> ChangeStreamIterable<TResult>
Creates a change stream for this client.withCodecRegistry
(CodecRegistry codecRegistry) Create a new MongoCluster instance with a different codec registry.withReadConcern
(ReadConcern readConcern) Create a new MongoCluster instance with a different read concern.withReadPreference
(ReadPreference readPreference) Create a new MongoCluster instance with a different read preference.withTimeout
(long timeout, TimeUnit timeUnit) Create a new MongoCluster instance with the set time limit for the full execution of an operation.withWriteConcern
(WriteConcern writeConcern) Create a new MongoCluster instance with a different write concern.
-
Method Details
-
getCodecRegistry
CodecRegistry getCodecRegistry()Get the codec registry for the MongoCluster.- Returns:
- the
CodecRegistry
- Since:
- 5.2
-
getReadPreference
ReadPreference getReadPreference()Get the read preference for the MongoCluster.- Returns:
- the
ReadPreference
- Since:
- 5.2
-
getWriteConcern
WriteConcern getWriteConcern()Get the write concern for the MongoCluster.- Returns:
- the
WriteConcern
- Since:
- 5.2
-
getReadConcern
ReadConcern getReadConcern()Get the read concern for the MongoCluster.- Returns:
- the
ReadConcern
- Since:
- 5.2
- MongoDB documentation
- Read Concern
-
getTimeout
The time limit for the full execution of an operation.If not null the following deprecated options will be ignored:
waitQueueTimeoutMS
,socketTimeoutMS
,wTimeoutMS
,maxTimeMS
andmaxCommitTimeMS
null
means that the timeout mechanism for operations will defer to using:waitQueueTimeoutMS
: The maximum wait time in milliseconds that a thread may wait for a connection to become availablesocketTimeoutMS
: How long a send or receive on a socket can take before timing out.wTimeoutMS
: How long the server will wait for the write concern to be fulfilled before timing out.maxTimeMS
: The cumulative time limit for processing operations on a cursor. See: cursor.maxTimeMS.maxCommitTimeMS
: The maximum amount of time to allow a singlecommitTransaction
command to execute. See:TransactionOptions.getMaxCommitTime(java.util.concurrent.TimeUnit)
.
0
means infinite timeout.> 0
The time limit to use for the full execution of an operation.
- Parameters:
timeUnit
- the time unit- Returns:
- the timeout in the given time unit
- Since:
- 5.2
-
withCodecRegistry
Create a new MongoCluster instance with a different codec registry.The
CodecRegistry
configured by this method is effectively treated by the driver as an instance ofCodecProvider
, whichCodecRegistry
extends. So there is no benefit to defining a class that implementsCodecRegistry
. Rather, an application should always createCodecRegistry
instances using the factory methods inCodecRegistries
.- Parameters:
codecRegistry
- the newCodecRegistry
for the database- Returns:
- a new MongoCluster instance with the different codec registry
- Since:
- 5.2
- See Also:
-
withReadPreference
Create a new MongoCluster instance with a different read preference.- Parameters:
readPreference
- the newReadPreference
for the database- Returns:
- a new MongoCluster instance with the different readPreference
- Since:
- 5.2
-
withWriteConcern
Create a new MongoCluster instance with a different write concern.- Parameters:
writeConcern
- the newWriteConcern
for the database- Returns:
- a new MongoCluster instance with the different writeConcern
- Since:
- 5.2
-
withReadConcern
Create a new MongoCluster instance with a different read concern.- Parameters:
readConcern
- the newReadConcern
for the database- Returns:
- a new MongoCluster instance with the different ReadConcern
- Since:
- 5.2
- MongoDB documentation
- Read Concern
-
withTimeout
Create a new MongoCluster instance with the set time limit for the full execution of an operation.0
means infinite timeout.> 0
The time limit to use for the full execution of an operation.
- Parameters:
timeout
- the timeout, which must be greater than or equal to 0timeUnit
- the time unit- Returns:
- a new MongoCluster instance with the set time limit for the full execution of an operation.
- Since:
- 5.2
- See Also:
-
getDatabase
Gets aMongoDatabase
instance for the given database name.- Parameters:
databaseName
- the name of the database to retrieve- Returns:
- a
MongoDatabase
representing the specified database - Throws:
IllegalArgumentException
- if databaseName is invalid- See Also:
-
startSession
ClientSession startSession()Creates a client session with default options.Note: A ClientSession instance can not be used concurrently in multiple operations.
- Returns:
- the client session
- Since server release
- 3.6
-
startSession
Creates a client session.Note: A ClientSession instance can not be used concurrently in multiple operations.
- Parameters:
options
- the options for the client session- Returns:
- the client session
- Since server release
- 3.6
-
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
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
- MongoDB documentation
- List Databases
- Since server release
- 3.6
-
listDatabases
ListDatabasesIterable<Document> listDatabases()Gets the list of databases- Returns:
- the list databases iterable interface
-
listDatabases
Gets the list of databases- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- the list databases iterable interface
- MongoDB documentation
- List Databases
- Since server release
- 3.6
-
listDatabases
Gets the list of databases- Type Parameters:
TResult
- the type of the class to use instead ofDocument
.- 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 ofDocument
.- Parameters:
clientSession
- the client session with which to associate this operationresultClass
- the class to cast the database documents to- Returns:
- the list databases iterable interface
- MongoDB documentation
- List Databases
- Since server release
- 3.6
-
watch
ChangeStreamIterable<Document> watch()Creates a change stream for this client.- Returns:
- the change stream iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-
watch
Creates a change stream for this client.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
resultClass
- the class to decode each document into- Returns:
- the change stream iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-
watch
Creates a change stream for this client.- Parameters:
pipeline
- the aggregation pipeline to apply to the change stream.- Returns:
- the change stream iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-
watch
<TResult> ChangeStreamIterable<TResult> watch(List<? extends Bson> pipeline, Class<TResult> resultClass) Creates a change stream for this client.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
pipeline
- the aggregation pipeline to apply to the change streamresultClass
- the class to decode each document into- Returns:
- the change stream iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-
watch
Creates a change stream for this client.- Parameters:
clientSession
- the client session with which to associate this operation- Returns:
- the change stream iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-
watch
<TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, Class<TResult> resultClass) Creates a change stream for this client.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
clientSession
- the client session with which to associate this operationresultClass
- the class to decode each document into- Returns:
- the change stream iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-
watch
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 iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-
watch
<TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, List<? extends Bson> pipeline, Class<TResult> resultClass) Creates a change stream for this client.- Type Parameters:
TResult
- the target document type of the iterable.- Parameters:
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- Returns:
- the change stream iterable
- Since:
- 3.8
- MongoDB documentation
- Change Streams
- Since server release
- 4.0
-