About the Kotlin SDK category

Discussion of the Couchbase Kotlin SDK and related projects.

We :heart: Kotlin, and we think you will too :slight_smile:

The Couchbase Kotlin SDK runs on the JVM. It’s built on top of the same high performance I/O core as the Couchbase Java SDK. It provides idiomatic Kotlin features like default arguments, suspend functions, and tasteful DSLs.

Documentation | API Reference | Code Samples | Source Code

Maven coordinates

  <version>...</version> ①

Latest Version


import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.query.execute
import kotlinx.coroutines.runBlocking

public fun main() {
    // Assumes you have Couchbase running locally
    // and the "travel-sample" sample bucket loaded.

    // Connect and open a bucket
    val cluster = Cluster.connect("", "Administrator", "password")
    try {
        val bucket = cluster.bucket("travel-sample")
        val collection = bucket.defaultCollection()

        runBlocking {
            // Perform a N1QL query and buffer the results
            val queryResult = cluster
                .query("select * from `travel-sample` limit 3")
            queryResult.rows.forEach { println(it) }

            // Get a document from the K/V service
            val getResult = collection.get("airline_10")
            println(getResult.contentAs<Map<String, Any?>>())
    } finally {
        runBlocking { cluster.disconnect() }
1 Like