viewQuery

fun viewQuery(designDocument: String, viewName: String, common: CommonOptions = CommonOptions.Default, serializer: JsonSerializer? = null, namespace: DesignDocumentNamespace = PRODUCTION, scanConsistency: ViewScanConsistency = ViewScanConsistency.updateAfter(), selection: ViewSelection = ViewSelection.range(), skip: Int = 0, limit: Int? = null, reduce: Boolean = true, group: ViewGroupLevel = ViewGroupLevel.none(), onError: ViewErrorMode = ViewErrorMode.CONTINUE, debug: Boolean = false, raw: Map<String, String>? = null): Flow<ViewFlowItem>

Queries a view on the bucket.

Samples

import com.couchbase.client.kotlin.Bucket
import com.couchbase.client.kotlin.view.DesignDocumentNamespace
import com.couchbase.client.kotlin.view.ViewMetadata
import com.couchbase.client.kotlin.view.ViewResult
import com.couchbase.client.kotlin.view.ViewSelection
import com.couchbase.client.kotlin.view.execute
fun main() { 
   //sampleStart 
   // Buffered view query, for when results are known to fit in memory
val result: ViewResult = bucket
    .viewQuery(
        designDocument = "myDesignDoc",
        viewName = "myView",
        namespace = DesignDocumentNamespace.DEVELOPMENT,
        selection = ViewSelection.key("foo")
    ).execute()
result.rows.forEach { println(it) }
println(result.metadata) 
   //sampleEnd
}
import com.couchbase.client.kotlin.Bucket
import com.couchbase.client.kotlin.view.DesignDocumentNamespace
import com.couchbase.client.kotlin.view.ViewMetadata
import com.couchbase.client.kotlin.view.ViewResult
import com.couchbase.client.kotlin.view.ViewSelection
import com.couchbase.client.kotlin.view.execute
fun main() { 
   //sampleStart 
   // Streaming view query, for when results are large or unbounded
val metadata: ViewMetadata = bucket
    .viewQuery(
        designDocument = "myDesignDoc",
        viewName = "myView",
        namespace = DesignDocumentNamespace.PRODUCTION,
        selection = ViewSelection.range(
            startKey = "somePrefix",
            endKey = "somePrefix\uefff"
        )
    ).execute { row -> println(row) }
println(metadata) 
   //sampleEnd
}

Throws

com.couchbase.client.core.error.ViewNotFoundException

if the view or design document is not found on the server.