createCollection

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:

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. Duration.ZERO (or null) means the collection's max expiry is always the same as the bucket's max expiry. If using Couchbase Server 7.6 or later, CollectionSpec.NEVER_EXPIRE (or -1 seconds) means documents in the collection never expire, regardless of the bucket's max expiry.

Throws

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

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