MongoClient

@Immutable
interface MongoClient : 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 serve as factories for {@code MongoDatabase} instances.

Since

3.0

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract override fun close()

Close the client, which will close all underlying cached resources, including, for example, sockets and background monitoring threads.

Link copied to clipboard
abstract fun getDatabase(name: String): MongoDatabase

Gets the database with the given name.

Link copied to clipboard
abstract fun listDatabaseNames(): Flow<String>
abstract fun listDatabaseNames(clientSession: ClientSession): Flow<String>

Get a list of the database names

Link copied to clipboard
abstract fun listDatabases(): ListDatabasesFlow<Document>
abstract fun listDatabases(clientSession: ClientSession): ListDatabasesFlow<Document>
abstract fun <TResult : Any> listDatabases(resultClass: KClass<out TResult>): ListDatabasesFlow<TResult>
abstract fun <TResult : Any> listDatabases(clientSession: ClientSession, resultClass: KClass<out TResult>): ListDatabasesFlow<TResult>

Gets the list of databases

Link copied to clipboard
abstract suspend fun startSession(): ClientSession

Creates a client session with default options.

abstract suspend fun startSession(options: ClientSessionOptions): ClientSession

Creates a client session.

Link copied to clipboard
abstract fun watch(): ChangeStreamFlow<Document>
abstract fun watch(clientSession: ClientSession): ChangeStreamFlow<Document>
abstract fun watch(pipeline: List<Bson>): ChangeStreamFlow<Document>
abstract fun <TResult : Any> watch(resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun watch(clientSession: ClientSession, pipeline: List<Bson>): ChangeStreamFlow<Document>
abstract fun <TResult : Any> watch(clientSession: ClientSession, resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun <TResult : Any> watch(pipeline: List<Bson>, resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun <TResult : Any> watch(    clientSession: ClientSession,     pipeline: List<Bson>,     resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>

Creates a change stream for this client.