MultiplatformMongoClient

Entry-point to the KtMongo Multiplatform driver.

The Multiplatform driver provides a coroutine-aware API which works on all supported Kotlin platforms.

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 = MongoClient(
hostname = "localhost",
port = 27017,
coroutineContext = currentCoroutineContext(),
)

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

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

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open suspend override fun close()
Link copied to clipboard
open override fun database(name: String): MultiplatformMongoDatabase

Creates a MultiplatformMongoDatabase object.

Link copied to clipboard
open override fun toString(): String