MongoClient

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

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
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
@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.