lookupIn

inline suspend fun <T, L : LookupInSpec> lookupIn(id: String, spec: L, common: CommonOptions = CommonOptions.Default, accessDeleted: Boolean = false, block: LookupInResult.() -> T): T

Retrieves specific fields of a document.

Samples

import com.couchbase.client.kotlin.Collection
import com.couchbase.client.kotlin.kv.LookupInSpec
fun main() { 
   //sampleStart 
   // Subdoc lookup
val spec = object : LookupInSpec() {
    val sku = get("sku")
    val hasPrice = exists("price")
    val orderCount = count("orders")
}
collection.lookupIn(documentId, spec) {
    println("cas: $cas")
    with(spec) {
        println("sku: ${sku.contentAs<String>()}")
        println("has price: ${hasPrice.value}")
        println("order count: ${orderCount.value}")
    }
} 
   //sampleEnd
}
import com.couchbase.client.kotlin.Collection
import com.couchbase.client.kotlin.kv.LookupInSpec
fun main() { 
   //sampleStart 
   // Subdoc lookup without Lambda
val spec = object : LookupInSpec() {
    val sku = get("sku")
    val hasPrice = exists("price")
    val orderCount = count("orders")
}
val result = collection.lookupIn(documentId, spec)
println("cas: $result.cas")
with(spec) {
    println("sku: ${sku.contentAs<String>(result)}")
    println("has price: ${hasPrice.get(result)}")
    println("order count: ${orderCount.get(result)}")
} 
   //sampleEnd
}

Parameters

block

callback for processing the results, with LookupInResult as the receiver.


suspend fun lookupIn(id: String, spec: LookupInSpec, common: CommonOptions = CommonOptions.Default, accessDeleted: Boolean = false): LookupInResult

Retrieves specific fields of a document.

Samples

import com.couchbase.client.kotlin.Collection
import com.couchbase.client.kotlin.kv.LookupInSpec
fun main() { 
   //sampleStart 
   // Subdoc lookup
val spec = object : LookupInSpec() {
    val sku = get("sku")
    val hasPrice = exists("price")
    val orderCount = count("orders")
}
collection.lookupIn(documentId, spec) {
    println("cas: $cas")
    with(spec) {
        println("sku: ${sku.contentAs<String>()}")
        println("has price: ${hasPrice.value}")
        println("order count: ${orderCount.value}")
    }
} 
   //sampleEnd
}
import com.couchbase.client.kotlin.Collection
import com.couchbase.client.kotlin.kv.LookupInSpec
fun main() { 
   //sampleStart 
   // Subdoc lookup without Lambda
val spec = object : LookupInSpec() {
    val sku = get("sku")
    val hasPrice = exists("price")
    val orderCount = count("orders")
}
val result = collection.lookupIn(documentId, spec)
println("cas: $result.cas")
with(spec) {
    println("sku: ${sku.contentAs<String>(result)}")
    println("has price: ${hasPrice.get(result)}")
    println("order count: ${orderCount.get(result)}")
} 
   //sampleEnd
}