CollectionManager

class CollectionManager

Manager for a bucket's scopes and collections.

Access via Bucket.collections.

Samples

import com.couchbase.client.kotlin.Bucket
import com.couchbase.client.kotlin.manager.collection.CollectionManager
import com.couchbase.client.kotlin.manager.collection.ScopeSpec
fun main() { 
   //sampleStart 
   // Create a new scope containing some collections
val manager: CollectionManager = bucket.collections

with(manager) {
    val scopeName = "tenant-a"
    createScope(scopeName)
    createCollection(scopeName = scopeName, collectionName = "widgets")
    createCollection(scopeName = scopeName, collectionName = "invoices")

    println(getScope(scopeName))
} 
   //sampleEnd
}
import com.couchbase.client.kotlin.Bucket
import com.couchbase.client.kotlin.manager.collection.CollectionManager
import com.couchbase.client.kotlin.manager.collection.ScopeSpec
fun main() { 
   //sampleStart 
   // Create a new scope using an existing scope as a template.
// (The new scope will have collections with the same names
// as the template's collections.)
val manager: CollectionManager = bucket.collections

val templateScopeSpec: ScopeSpec = manager.getScope("existing-scope")
val nameOfNewScope = "new-scope"
manager.createScope(nameOfNewScope)
templateScopeSpec.collections
    .filter { it.name != "_default" } // can't create default collection
    .forEach { manager.createCollection(it.copy(scopeName = nameOfNewScope)) } 
   //sampleEnd
}

Functions

Link copied to clipboard
suspend fun createCollection(collection: CollectionSpec, common: CommonOptions = CommonOptions.Default)

Creates a collection in an existing scope.

suspend fun createCollection(scopeName: String, collectionName: String, common: CommonOptions = CommonOptions.Default, maxExpiry: Duration? = null, @SinceCouchbase(value = "7.2") history: Boolean? = null)

Creates a collection in an existing scope. Equivalent to:

Link copied to clipboard
suspend fun createScope(scopeName: String, common: CommonOptions = CommonOptions.Default)

Creates a scope in the bucket.

Link copied to clipboard
suspend fun dropCollection(collection: CollectionSpec, common: CommonOptions = CommonOptions.Default)

Deletes a collection from a scope. Equivalent to:

suspend fun dropCollection(scopeName: String, collectionName: String, common: CommonOptions = CommonOptions.Default)

Deletes a collection from a scope.

Link copied to clipboard
suspend fun dropScope(scopeName: String, common: CommonOptions = CommonOptions.Default)

Deletes a scope from the bucket.

Link copied to clipboard
suspend fun getAllScopes(common: CommonOptions = CommonOptions.Default): List<ScopeSpec>

Returns information about all scopes (and their collections) in the bucket.

Link copied to clipboard
suspend fun getScope(scopeName: String, common: CommonOptions = CommonOptions.Default): ScopeSpec

Returns information about a scope and its collections.

Link copied to clipboard
@SinceCouchbase(value = "7.2")
suspend fun updateCollection(scopeName: String, collectionName: String, common: CommonOptions = CommonOptions.Default, @SinceCouchbase(value = "7.6") maxExpiry: Duration? = null, history: Boolean? = null)

Modifies an existing collection.