Documentation

Collection
in package
implements CollectionInterface

Collection is an object containing functionality for performing KeyValue operations against the server.

Interfaces, Classes, Traits and Enums

CollectionInterface

Table of Contents

$bucketName  : string
$core  : resource
$name  : string
$observability  : ObservabilityContext
$scopeName  : string
binary()  : BinaryCollection
Creates and returns a BinaryCollection object for use with binary type documents.
bucketName()  : string
Get the name of the bucket.
exists()  : ExistsResult
Checks if a document exists on the server.
get()  : GetResult
Gets a document from the server.
getAllReplicas()  : array<string|int, mixed>
Gets a document from the active server and all replica servers in the cluster.
getAndLock()  : GetResult
Gets a document from the server, locking the document so that no other processes can perform mutations against it.
getAndTouch()  : GetResult
Gets a document from the server and simultaneously updates its expiry time.
getAnyReplica()  : GetReplicaResult
Gets a document from any replica server in the cluster.
getMulti()  : array<string|int, GetResult>
Retrieves a group of documents. If the document does not exist, it will not raise an exception, but rather fill non-null value in error() property of the corresponding result object.
insert()  : MutationResult
Inserts a document if it doesn't exist, errors if it does exist.
lookupIn()  : LookupInResult
Performs a set of subdocument lookup operations against the document.
lookupInAllReplicas()  : array<string|int, mixed>
Performs a set of subdocument lookup operations against the document from the active server and all replicas in the cluster.
lookupInAnyReplica()  : LookupInReplicaResult
Performs a set of subdocument lookup operations against the document from any replica server in the cluster.
mutateIn()  : MutateInResult
Performs a set of subdocument lookup operations against the document.
name()  : string
Get the name of the collection.
queryIndexes()  : CollectionQueryIndexManager
Creates a new manager object for managing N1QL query indexes at the collection level
remove()  : MutationResult
Removes a document.
removeMulti()  : array<string|int, MutationResult>
Removes a group of documents. If second element of the entry (CAS) is null, then the operation will remove the document unconditionally.
replace()  : MutationResult
Replaces a document if it exists, errors if it doesn't exist.
scan()  : ScanResults
Performs a key-value scan operation
scopeName()  : string
Get the name of the scope.
touch()  : MutationResult
Touches a document, setting a new expiry time.
unlock()  : Result
Unlocks a document which was locked using getAndLock. This frees the document to be modified by other processes.
upsert()  : MutationResult
Creates a document if it doesn't exist, otherwise updates it.
upsertMulti()  : array<string|int, MutationResult>
Creates a group of documents if they don't exist, otherwise updates them.

Properties

Methods

bucketName()

Get the name of the bucket.

public bucketName() : string
Tags
since
4.0.0
Return values
string —

get()

Gets a document from the server.

public get(string $id[, GetOptions|null $options = null ]) : GetResult

This can take 3 paths:

  • a standard full document fetch,
  • a subdocument full document fetch also fetching document expiry (when withExpiry is set),
  • or a subdocument fetch (when projections are used).
Parameters
$id : string

the key of the document to fetch

$options : GetOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
GetResult —

getAllReplicas()

Gets a document from the active server and all replica servers in the cluster.

public getAllReplicas(string $id[, GetAllReplicasOptions|null $options = null ]) : array<string|int, mixed>

Returns an array of documents, one per server.

Parameters
$id : string

the key of the document

$options : GetAllReplicasOptions|null = null

the options to use for the operation

Tags
throws
CouchbaseException
throws
TimeoutException
since
4.0.0
Return values
array<string|int, mixed> —

getAndLock()

Gets a document from the server, locking the document so that no other processes can perform mutations against it.

public getAndLock(string $id, int $lockTimeSeconds[, GetAndLockOptions|null $options = null ]) : GetResult
Parameters
$id : string

the key of the document to get

$lockTimeSeconds : int

the length of time to lock the document in seconds

$options : GetAndLockOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
GetResult —

getAndTouch()

Gets a document from the server and simultaneously updates its expiry time.

public getAndTouch(string $id, int|DateTimeInterface $expiry[, GetAndTouchOptions|null $options = null ]) : GetResult
Parameters
$id : string

the key of the document

$expiry : int|DateTimeInterface

the length of time to update the expiry to in seconds, or epoch timestamp

$options : GetAndTouchOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
GetResult —

getMulti()

Retrieves a group of documents. If the document does not exist, it will not raise an exception, but rather fill non-null value in error() property of the corresponding result object.

public getMulti(array<string|int, mixed> $ids[, GetOptions|null $options = null ]) : array<string|int, GetResult>
Parameters
$ids : array<string|int, mixed>

array of IDs, organized like this ["key1", "key2", ...]

$options : GetOptions|null = null

the options to use for the operation

Tags
since
4.0.0
Return values
array<string|int, GetResult> —

array of GetResult, one for each of the entries

lookupIn()

Performs a set of subdocument lookup operations against the document.

public lookupIn(string $id, array<string|int, LookupInSpec> $specs[, LookupInOptions|null $options = null ]) : LookupInResult
Parameters
$id : string

the key of the document

$specs : array<string|int, LookupInSpec>

the array of selectors to query against the document

$options : LookupInOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
LookupInResult —

lookupInAllReplicas()

Performs a set of subdocument lookup operations against the document from the active server and all replicas in the cluster.

public lookupInAllReplicas(string $id, array<string|int, LookupInSpec> $specs[, LookupInAllReplicasOptions|null $options = null ]) : array<string|int, mixed>

Returns an array of LookupInReplicaResults, one per server.

Parameters
$id : string

the key of the document

$specs : array<string|int, LookupInSpec>

the array of selectors to query against the document

$options : LookupInAllReplicasOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
TimeoutException
throws
CouchbaseException
since
4.1.6
Return values
array<string|int, mixed> —

lookupInAnyReplica()

Performs a set of subdocument lookup operations against the document from any replica server in the cluster.

public lookupInAnyReplica(string $id, array<string|int, LookupInSpec> $specs[, LookupInAnyReplicaOptions|null $options = null ]) : LookupInReplicaResult
Parameters
$id : string

the key of the document

$specs : array<string|int, LookupInSpec>

the array of selectors to query against the document

$options : LookupInAnyReplicaOptions|null = null

the options to use for the operation

Tags
throws
DocumentIrretrievableException
throws
TimeoutException
throws
CouchbaseException
since
4.1.6
Return values
LookupInReplicaResult —

mutateIn()

Performs a set of subdocument lookup operations against the document.

public mutateIn(string $id, array<string|int, MutateInSpec> $specs[, MutateInOptions|null $options = null ]) : MutateInResult
Parameters
$id : string

the key of the document

$specs : array<string|int, MutateInSpec>

the array of modifications to perform against the document

$options : MutateInOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
DocumentExistsException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
MutateInResult —

name()

Get the name of the collection.

public name() : string
Tags
since
4.0.0
Return values
string —

removeMulti()

Removes a group of documents. If second element of the entry (CAS) is null, then the operation will remove the document unconditionally.

public removeMulti(array<string|int, mixed> $entries[, RemoveOptions|null $options = null ]) : array<string|int, MutationResult>
Parameters
$entries : array<string|int, mixed>

array of arrays, organized like this [["key1", "encodedCas1"], ["key2", "encodedCas2"], ...] or ["key1", "key2", ...]

$options : RemoveOptions|null = null

the options to use for the operation

Tags
throws
UnsupportedOperationException
since
4.0.0
Return values
array<string|int, MutationResult> —

array of MutationResult, one for each of the entries

replace()

Replaces a document if it exists, errors if it doesn't exist.

public replace(string $id, mixed $value[, ReplaceOptions|null $options = null ]) : MutationResult
Parameters
$id : string

the key of the document

$value : mixed

the value to use for the document

$options : ReplaceOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
CasMismatchException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
MutationResult —

scan()

Performs a key-value scan operation

public scan(ScanType $scanType[, ScanOptions|null $options = null ]) : ScanResults

Use this API for low concurrency batch queries where latency is not a critical as the system may have to scan a lot of documents to find the matching documents. For low latency range queries, it is recommended that you use SQL++ with the necessary indexes.

Parameters
$scanType : ScanType

The type of scan to execute

$options : ScanOptions|null = null

The options to use for the operation

Tags
throws
InvalidArgumentException
since
4.1.6
Return values
ScanResults —

Object containing iterator over the scan results

scopeName()

Get the name of the scope.

public scopeName() : string
Tags
since
4.0.0
Return values
string —

touch()

Touches a document, setting a new expiry time.

public touch(string $id, int|DateTimeInterface $expiry[, TouchOptions|null $options = null ]) : MutationResult
Parameters
$id : string

the key of the document

$expiry : int|DateTimeInterface

the expiry time for the document in ms

$options : TouchOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
MutationResult —

unlock()

Unlocks a document which was locked using getAndLock. This frees the document to be modified by other processes.

public unlock(string $id, string $cas[, UnlockOptions|null $options = null ]) : Result
Parameters
$id : string

the key of the document

$cas : string

the current cas value of the document

$options : UnlockOptions|null = null

the options to use for the operation

Tags
throws
DocumentNotFoundException
throws
CasMismatchException
throws
TimeoutException
throws
CouchbaseException
since
4.0.0
Return values
Result —

upsertMulti()

Creates a group of documents if they don't exist, otherwise updates them.

public upsertMulti(array<string|int, mixed> $entries[, UpsertOptions|null $options = null ]) : array<string|int, MutationResult>
Parameters
$entries : array<string|int, mixed>

array of arrays, organized like this [["key1", $value1], ["key2", $value2], ...]

$options : UpsertOptions|null = null

the options to use for the operation

Tags
throws
InvalidArgumentException
since
4.0.0
Return values
array<string|int, MutationResult> —

array of MutationResult, one for each of the entries


        

Search results