Kotlin coroutine support for MongoDB built on top of the official MongoDB Reactive Streams Java Driver.
build.gradle.kts
:
dependencies {
implementation("io.fluidsonic.mongo:fluid-mongo:1.7.0")
}
import io.fluidsonic.mongo.MongoClients
import org.bson.Document
suspend fun main() {
val collection = MongoClients.create()
.getDatabase("test")
.getCollection("test")
collection.insertOne(mapOf("hello" to "world")) // suspending call
collection.insertOne(mapOf("it's" to "so easy!")) // suspending call
collection.find().collect { document -> // Kotlin Flow
println(document)
}
}
Output:
Document{{_id=5bb6b56f9cfa62686b5afc87, hello=world}}
Document{{_id=5bb6b56f9cfa62686b5afc88, it's=so easy!}}
Apache 2.0