create Collection
suspend fun createCollection(scopeName: String, collectionName: String, common: CommonOptions = CommonOptions.Default, maxExpiry: Duration? = null)
Content copied to clipboard
Creates a collection in an existing scope. Equivalent to:
createCollection(CollectionSpec(scopeName, collectionName, maxExpiry))
Content copied to clipboard
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
scope Name
Name of the parent scope. This scope must already exist.
collection Name
Name of the collection to create.
max Expiry
Maximum expiry for documents in the collection, or null if unlimited.
Throws
com. couchbase. client. core. error. Scope Not Found Exception
if the parent scope does not exist.
com. couchbase. client. core. error. Collection Exists Exception
if there is already a collection with the same name in the parent scope.
suspend fun createCollection(collection: CollectionSpec, common: CommonOptions = CommonOptions.Default)
Content copied to clipboard
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. Scope Not Found Exception
if the parent scope does not exist.
com. couchbase. client. core. error. Collection Exists Exception
if there is already a collection with the same name in the parent scope.