Datastructures

CouchbaseList

class couchbase.datastructures.CouchbaseList(key, collection)

CouchbaseList provides a simplified interface for storing lists within a Couchbase document.

Parameters:
  • key (str) – Document key to use for the list.

  • collection (Collection) – The Collection where the list belongs

append(value) None

Add an item to the end of the list.

Parameters:

value (JSONType) – The value to add.

clear() None

Clears the list.

Raises:

DocumentNotFoundException – If the list does not already exist.

get_all() List[Any]

Returns the entire list of items in this list.

Returns:

The entire list.

Return type:

int

get_at(index) Any

Retrieves the item at a specific index in the list.

Parameters:

index (int) – The index to retrieve.

Returns:

The value of the element at the specified index.

Return type:

Any

Raises:

InvalidArgumentException – If the index is out of range.

index_of(value) int

Returns the index of a specific value from the list.

Parameters:

value (JSONType) – The value to search for.

Returns:

The index of the value in the list. Returns -1 if value is not found.

Return type:

int

prepend(value) None

Add an item to the beginning of the list.

Parameters:

value (JSONType) – The value to add.

remove_at(index) None

Removes an item at a specific index from the list.

Parameters:

index (int) – The index to remove.

Raises:

InvalidArgumentException – If the index is out of range.

set_at(index, value) None

Sets an item within a list at a specified index.

Parameters:
  • index (int) – The index to retrieve.

  • value (JSONType) – The value to set.

Raises:

InvalidArgumentException – If the index is out of range.

size() int

Returns the number of items in the list.

Returns:

The number of items in the list.

Return type:

int

CouchbaseMap

class couchbase.datastructures.CouchbaseMap(key, collection)

CouchbaseMap provides a simplified interface for storing a map within a Couchbase document.

Parameters:
  • key (str) – Document key to use for the map.

  • collection (Collection) – The Collection where the map belongs

add(mapkey, value) None

Sets a specific key to the specified value in the map.

Parameters:
  • mapkey (str) – The key to set.

  • value (JSONType) – The value to set.

clear() None

Clears the map.

exists(key) bool

Checks whether a specific key exists in the map.

Parameters:

key (str) – The key to set.

Returns:

True if the key exists in the map, False otherwise.

Return type:

bool

get(mapkey) Any

Fetches a specific key from the map.

Parameters:

mapkey (str) – The key to fetch.

Returns:

The value of the specified key.

Return type:

Any

get_all() Dict[str, Any]

Retrieves the entire map.

Returns:

The entire CouchbaseMap.

Return type:

Dict[str, Any]

items() Generator

Provides mechanism to loop over the entire map.

Returns:

A generator expression for the map

Return type:

Generator

keys() List[str]

Returns a list of all the keys which exist in the map.

Returns:

A list of all the keys that exist in the map.

Return type:

List[str]

remove(mapkey) None

Removes a specific key from the map.

Parameters:

mapkey (str) – The key in the map to remove.

Raises:

InvalidArgumentException – If the key is not in the map.

size() int

Returns the number of items in the map.

Returns:

The number of items in the map.

Return type:

int

values() List[Any]

Returns a list of all the values which exist in the map.

Returns:

A list of all the values that exist in the map.

Return type:

List[Any]

CouchbaseSet

class couchbase.datastructures.CouchbaseSet(key, collection)

CouchbaseSet provides a simplified interface for storing a set within a Couchbase document.

Parameters:
  • key (str) – Document key to use for the set.

  • collection (Collection) – The Collection where the set belongs.

add(value) bool

Adds a new item to the set. Returning whether the item already existed in the set or not.

Parameters:

value (Any)

Returns:

True if the value was added, False otherwise (meaning the value already

exists in the set).

Return type:

bool

clear() None

Clears the set.

contains(value) bool

Returns whether a specific value already exists in the set.

Parameters:

value (Any) – The value to check for existence.

Returns:

True if the specified value exists in the set. False otherwise.

Return type:

bool

remove(value, timeout=None) None

Removes a specific value from the set.

Parameters:
  • value (Any) – The value to remove

  • timeout (timedelta, optional) – Amount of time allowed when attempting to remove the value. Defaults to 10 seconds.

size() int

Returns the number of items in the set.

Returns:

The number of items in the set.

Return type:

int

values() List[Any]

Returns a list of all the values which exist in the set.

Returns:

The values that exist in the set.

Return type:

List[Any]

CouchbaseQueue

class couchbase.datastructures.CouchbaseQueue(key, collection)

CouchbaseQueue provides a simplified interface for storing a queue within a Couchbase document.

Parameters:
  • key (str) – Document key to use for the queue.

  • collection (Collection) – The Collection where the queue belongs.

clear() None

Clears the queue.

pop(timeout=None) Any

Removes an item from the front of the queue.

Parameters:

timeout (timedelta, optional) – Amount of time allowed when attempting to remove the value. Defaults to 10 seconds.

Returns:

The value that was removed from the front of the queue.

Return type:

Any

push(value) None

Adds a new item to the back of the queue.

Parameters:

value (JSONType) – The value to push onto the queue.

size() int

Returns the number of items in the queue.

Returns:

The number of items in the queue.

Return type:

int