CoroutineMongoClient

Entry-point to the KtMongo Coroutines driver.

The Coroutine client provides a coroutine-aware API which internally uses the official Kotlin driver.

Organizing data

Accessing MongoDB data happens in three steps:

Example

@Serializable
class User(
val _id: ObjectId,
val name: String,
val age: Int,
)

fun main() = runBlocking {
val client = CoroutineMongoClient("mongodb://localhost:27017")

val database = client.database("my-app")
val users = database.collection<User>("users")

println("The database contains ${users.count()} users.")
}

See also

Convert an existing instance from the official Kotlin driver.

Functions

Link copied to clipboard
abstract fun asOfficial(): MongoClient

Obtains the underlying MongoDB client from the official Kotlin driver.

Link copied to clipboard
abstract fun close()
Link copied to clipboard
abstract override fun database(name: String): CoroutineMongoDatabase