lookupInAnyReplica

@SinceCouchbase(value = "7.6")
inline suspend fun <T, L : LookupInSpec> lookupInAnyReplica(id: String, spec: L, common: CommonOptions = CommonOptions.Default, readPreference: ReadPreference = ReadPreference.none(), block: LookupInReplicaResult.() -> T): T

Like lookupIn, but sends the request to all replicas in addition to the active. Returns the result from whichever server node responded quickest.

Parameters

block

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

Throws

DocumentUnretrievableException

if the document could not be retrieved from at least one location.

Samples

// 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}")
    }
}
// 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)}")
}

@SinceCouchbase(value = "7.6")
suspend fun lookupInAnyReplica(id: String, spec: LookupInSpec, common: CommonOptions = CommonOptions.Default, readPreference: ReadPreference = ReadPreference.none()): LookupInReplicaResult

Like lookupIn, but sends the request to all replicas in addition to the active. Returns the result from whichever server node responded quickest.

Throws

DocumentUnretrievableException

if the document could not be retrieved from at least one location.

Samples

// 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)}")
}