upsertUser

suspend fun upsertUser(user: User, common: CommonOptions = CommonOptions.Default)

Samples

import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.manager.user.Role
import com.couchbase.client.kotlin.manager.user.User
fun main() { 
   //sampleStart 
   // Create a new user
cluster.users.upsertUser(
    User(
        username = "alice",
        password = "swordfish",
        roles = setOf(Role("data_reader", bucket = "*"))
    )
) 
   //sampleEnd
}
import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.manager.user.Role
import com.couchbase.client.kotlin.manager.user.User
fun main() { 
   //sampleStart 
   // Add a new role to an existing user
// (must get existing user first, otherwise existing values are clobbered)
val user = cluster.users.getUser("alice").user
cluster.users.upsertUser(
    user.copy(roles = user.roles + Role("data_writer", bucket = "*"))
) 
   //sampleEnd
}
import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.manager.user.Role
import com.couchbase.client.kotlin.manager.user.User
fun main() { 
   //sampleStart 
   // Change the password of an existing user
// (must get existing user first, otherwise existing values are clobbered)
val user = cluster.users.getUser("alice").user
cluster.users.upsertUser(
    user.copy(password = "correct horse battery staple")
) 
   //sampleEnd
}