getReplicaFromPreferredServerGroup

Gets a document (possibly a replica) from the specified Couchbase collection matching the specified id.

It will be fetched only from nodes in the preferred server group, which can be configured with the preferredServerGroup client setting. If this client setting is unset or refers to a nonexistent server group, or if no node in group has the document, then DocumentUnretrievableException is thrown.

It is strongly recommended to that this method always be used with a fallback strategy, like:

val result = try {
getReplicaFromPreferredServerGroup(collection, id)
} catch (e: DocumentUnretrievableException) {
get(collection, id)
}

Parameters

collection

the Couchbase collection containing the document

id

the ID of the document to get

Throws

DocumentUnretrievableException

if for any reason the document cannot be fetched.

Samples

// Configure the preferred server group
val cluster = Cluster.connect("127.0.0.1", "Administrator", "password") {
    preferredServerGroup = "Group 1"
}