Counter

class Counter

A counter backed by a document on Couchbase Server.

Create an instance using Collection.counter.

Counter operations are atomic with respect to a single Couchbase Server cluster, but not between clusters when Cross-Datacenter Replication (XDCR) is used.

The content of a counter document is a single JSON integer with a minimum value of zero and a maximum value of 2^64 - 1.

A counter decremented below zero is reset to zero.

A counter incremented above 2^64 - 1 overflows (wraps around).

Counter values above 2^53 - 1 may have interoperability issues with other languages that store all numbers as floating point values.

See also

Functions

Link copied to clipboard
suspend fun addAndGet(delta: Long): ULong

Atomically adds the given delta to the current value.

Link copied to clipboard
suspend fun decrementAndGet(): ULong

Atomically decrements by one the current value.

Link copied to clipboard
suspend fun get(): ULong

Returns the current value of the counter.

Link copied to clipboard
suspend fun incrementAndGet(): ULong

Atomically increments by one the current value.

Link copied to clipboard
suspend fun set(value: ULong): MutationResult

Sets the value of the counter.

Link copied to clipboard
open override fun toString(): String

Properties

Link copied to clipboard
val collection: Collection
Link copied to clipboard
val common: CommonOptions
Link copied to clipboard
val documentId: String
Link copied to clipboard
val durability: Durability
Link copied to clipboard
val expiry: Expiry