Skip to content

KtMongo

object KtMongo

Entry-point to convert objects from the official drivers to the KtMongo library.

To learn more about the syntax of the different operators, see the top-level functions in this package.

Functions

from

@JvmStatic
fun <T : Any> from(driver: MongoCollection<T>): JvmMongoCollection<T>

Converts a Java MongoDB collection into a KtMongo collection.

Example (Java)
try (var client = MongoClients.create()) {
    var javaCollection = client.getDatabase("my-db")
        .getCollection("my-col", MyCollection.class);

    var collection = KtMongo.from(javaCollection);

    System.out.println(
        collection.find().toList()
    );
}
@JvmStatic
fun <T : Any> from(driver: MongoCollection<T>): JvmMongoCollection<T>

Converts a Kotlin MongoDB collection into a KtMongo collection.

Example (Kotlin)
MongoClients.create().use { client ->
    val kotlinCollection = it.getDatabase("my-db")
        .getCollection("my-col", MyCollection::class.java)

    val collection = KtMongo.from(kotlinCollection)

    println(
        collection.find().toList()
    )
}