Range Scan

Note

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.

Scan Types

ScanTerm

class couchbase.kv_range_scan.ScanTerm(term, exclusive=None)

Represents a search term for a RangeScan

RangeScan

class couchbase.kv_range_scan.RangeScan
property start: ScanTerm
property end: ScanTerm

PrefixScan

class couchbase.kv_range_scan.PrefixScan
property prefix: str

SamplingScan

class couchbase.kv_range_scan.SamplingScan
property limit: int
property seed: int | None

Options

class couchbase.options.ScanOptions(timeout=None, ids_only=None, consistent_with=None, batch_byte_limit=None, batch_item_limit=None, batch_time_limit=None, transcoder=None, concurrency=None, span=None)

Available options to for a key-value scan operation.

Warning

Importing options from couchbase.collection is deprecated. All options should be imported from couchbase.options.

Parameters:
  • timeout (timedelta, optional) – The timeout for this operation. Defaults to global range scan operation timeout.

  • ids_only (bool, optional) – Specifies that scan should only return document ids. Defaults to False.

  • consistent_with (MutationState, optional) – Specifies a MutationState which the scan should be consistent with. Defaults to None.

  • batch_byte_limit (int, optional) – The limit applied to the number of bytes returned from the server for each partition batch. Defaults to 15k.

  • batch_item_limit (int, optional) – The limit applied to the number of items returned from the server for each partition batch. Defaults to 50.

  • transcoder (Transcoder, optional) – Specifies an explicit transcoder to use for this specific operation. Defaults to JsonTranscoder.

  • concurrency (int, optional) – The upper bound on the number of vbuckets that should be scanned in parallel. Defaults to 1.

Results

ScanResult

class couchbase.result.ScanResult
property id: str | None

Id for the operation, if it exists.

Type:

Optional[str]

property ids_only: bool

True is KV range scan request options set ids_only to True. False otherwise.

Type:

bool

property cas: int

The CAS of the document, if it exists

Type:

Optional[int]

property content_as: Any

The contents of the document.

Get the value as a dict:

res = collection.get(key)
value = res.content_as[dict]
Raises:

InvalidArgumentException – If called when KV range scan options set without_content to True.

Type:

Any

property expiry_time: datetime | None

The expiry of the document, if it was requested.

Type:

Optional[datetime]

ScanResultIterable

class couchbase.result.ScanResultIterable
rows()

The rows which have been returned by the query.

Note

If using the acouchbase API be sure to use async for when looping over rows.

Returns:

Either an iterable or async iterable.

Return type:

Iterable

cancel_scan()