MongoClient

class MongoClient(wrapped: MongoClient) : MongoCluster, 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.

Instances of this class serve as factories for MongoDatabase instances. Instances of this class can be created via the MongoClient.create helpers

See also

Constructors

Link copied to clipboard
constructor(wrapped: MongoClient)

Types

Link copied to clipboard
object Factory

A factory for MongoClient instances.

Functions

Link copied to clipboard
suspend fun bulkWrite(models: List<ClientNamespacedWriteModel>): ClientBulkWriteResult

Executes a client-level bulk write operation. This method is functionally equivalent to bulkWrite(models, options) with the default options.

suspend fun bulkWrite(clientSession: ClientSession, models: List<ClientNamespacedWriteModel>): ClientBulkWriteResult

Executes a client-level bulk write operation. This method is functionally equivalent to bulkWrite(clientSession, models, options) with the default options.

suspend fun bulkWrite(models: List<ClientNamespacedWriteModel>, options: ClientBulkWriteOptions): ClientBulkWriteResult
suspend fun bulkWrite(clientSession: ClientSession, models: List<ClientNamespacedWriteModel>, options: ClientBulkWriteOptions): ClientBulkWriteResult

Executes a client-level bulk write operation.

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun getClusterDescription(): ClusterDescription

Gets the current cluster description.

Link copied to clipboard
fun getDatabase(databaseName: String): MongoDatabase

Gets a MongoDatabase instance for the given database name.

Link copied to clipboard

Get a list of the database names

fun listDatabaseNames(clientSession: ClientSession): Flow<String>

Gets the list of databases

Link copied to clipboard
@JvmName(name = "listDatabasesAsDocument")
fun listDatabases(): ListDatabasesFlow<Document>
@JvmName(name = "listDatabasesAsDocumentWithSession")
fun listDatabases(clientSession: ClientSession): ListDatabasesFlow<Document>
inline fun <T : Any> listDatabases(clientSession: ClientSession): ListDatabasesFlow<T>
fun <T : Any> listDatabases(resultClass: Class<T>): ListDatabasesFlow<T>
fun <T : Any> listDatabases(clientSession: ClientSession, resultClass: Class<T>): ListDatabasesFlow<T>

Gets the list of databases

Link copied to clipboard
suspend fun startSession(options: ClientSessionOptions = ClientSessionOptions.builder().build()): ClientSession

Creates a client session.

Link copied to clipboard
@Alpha(value = [Reason.CLIENT])
fun timeout(timeUnit: TimeUnit = TimeUnit.MILLISECONDS): Long?

The time limit for the full execution of an operation.

Link copied to clipboard
@JvmName(name = "watchAsDocument")
fun watch(pipeline: List<Bson> = emptyList()): ChangeStreamFlow<Document>
inline fun <T : Any> watch(pipeline: List<Bson> = emptyList()): ChangeStreamFlow<T>
@JvmName(name = "watchAsDocumentWithSession")
fun watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList()): ChangeStreamFlow<Document>
inline fun <T : Any> watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList()): ChangeStreamFlow<T>
fun <T : Any> watch(pipeline: List<Bson> = emptyList(), resultClass: Class<T>): ChangeStreamFlow<T>
fun <T : Any> watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList(), resultClass: Class<T>): ChangeStreamFlow<T>

Creates a change stream for this client.

Link copied to clipboard
fun withCodecRegistry(newCodecRegistry: CodecRegistry): MongoCluster

Create a new MongoCluster instance with a different codec registry.

Link copied to clipboard
fun withReadConcern(newReadConcern: ReadConcern): MongoCluster

Create a new MongoCluster instance with a different read concern.

Link copied to clipboard
fun withReadPreference(newReadPreference: ReadPreference): MongoCluster

Create a new MongoCluster instance with a different read preference.

Link copied to clipboard
@Alpha(value = [Reason.CLIENT])
fun withTimeout(timeout: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS): MongoCluster

Create a new MongoCluster instance with the set time limit for the full execution of an operation.

Link copied to clipboard
fun withWriteConcern(newWriteConcern: WriteConcern): MongoCluster

Create a new MongoCluster instance with a different write concern.

Properties

Link copied to clipboard
val codecRegistry: CodecRegistry

The codec registry.

Link copied to clipboard
val readConcern: ReadConcern

The read concern.

Link copied to clipboard
val readPreference: ReadPreference

The read preference.

Link copied to clipboard
val writeConcern: WriteConcern

The write concern.