createCollection

suspend fun createCollection(scopeName: String, collectionName: String, common: CommonOptions = CommonOptions.Default, maxExpiry: Duration? = null)

Creates a collection in an existing scope. Equivalent to:

createCollection(CollectionSpec(scopeName, collectionName, maxExpiry))

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
}

Parameters

scopeName

Name of the parent scope. This scope must already exist.

collectionName

Name of the collection to create.

maxExpiry

Maximum expiry for documents in the collection, or null if unlimited.

Throws

com.couchbase.client.core.error.ScopeNotFoundException

if the parent scope does not exist.

com.couchbase.client.core.error.CollectionExistsException

if there is already a collection with the same name in the parent scope.


suspend fun createCollection(collection: CollectionSpec, common: CommonOptions = CommonOptions.Default)

Creates a collection in an existing scope.

Parameters

collection

Specifies the collection to create. The parent scope must already exist.

Throws

com.couchbase.client.core.error.ScopeNotFoundException

if the parent scope does not exist.

com.couchbase.client.core.error.CollectionExistsException

if there is already a collection with the same name in the parent scope.