Bucket
- class couchbase.bucket.Bucket(cluster: Cluster, bucket_name: str)
Create a Couchbase Bucket instance.
Exposes the operations which are available to be performed against a bucket. Namely the ability to access to Collections as well as performing management operations against the bucket.
- Parameters:
- Raises:
BucketNotFoundException – If provided bucket_name cannot be found.
- close() None
Shuts down this bucket instance. Cleaning up all resources associated with it.
Warning
Use of this method is almost always unnecessary. Bucket resources should be cleaned up once the bucket instance falls out of scope. However, in some applications tuning resources is necessary and in those types of applications, this method might be beneficial.
- collection(collection_name: str) Collection
Creates a
Collectioninstance of the specified collection.- Parameters:
collection_name (str) – Name of the collection to reference.
- Returns:
A
Collectioninstance of the specified collection.- Return type:
- collections() CollectionManager
Get a manager for the scopes and collections of this bucket.
- Returns:
A
CollectionManagerinstance.- Return type:
- default_collection() Collection
Creates a
Collectioninstance of the default collection.- Returns:
A
Collectioninstance of the default collection.- Return type:
- ping(opts: PingOptions | None = None, **kwargs: Unpack[PingOptionsKwargs]) PingResult
Performs a ping operation against the bucket.
The ping operation pings the services which are specified (or all services if none are specified). Returns a report which describes the outcome of the ping operations which were performed.
- Parameters:
opts (
PingOptions) – Optional parameters for this operation.**kwargs – keyword arguments that can be used in place or to override provided
PingOptions
- Returns:
A report which describes the outcome of the ping operations which were performed.
- Return type:
- view_indexes() ViewIndexManager
Get a manager for the view design documents and views of this bucket.
Deprecated since version 4.6.0: Views are deprecated in Couchbase Server 7.0+, and will be removed from a future server version. Views are not compatible with the Magma storage engine. Instead of views, use indexes and queries using the Index Service (GSI) and the Query Service (SQL++).
- Returns:
A
ViewIndexManagerinstance.- Return type:
- view_query(design_doc: str, view_name: str, view_options: ViewOptions | None = None, **kwargs: Unpack[ViewOptionsKwargs]) ViewResult
Executes a View query against the bucket.
Deprecated since version 4.6.0: Views are deprecated in Couchbase Server 7.0+, and will be removed from a future server version. Views are not compatible with the Magma storage engine. Instead of views, use indexes and queries using the Index Service (GSI) and the Query Service (SQL++).
Note
The query is executed lazily in that it is executed once iteration over the
ViewResultbegins.See also
ViewIndexManager: for how to manage design documents
- Parameters:
design_doc (str) – The name of the design document containing the view to execute.
view_name (str) – The name of the view to execute.
view_options (
ViewOptions) – Optional parameters for the view query operation.**kwargs – keyword arguments that can be used in place or to override provided
ViewOptions
- Returns:
An instance of a
ViewResultwhich provides access to iterate over the query results and access metadata about the query.- Return type:
Examples
Simple view query:
from couchbase.management.views import DesignDocumentNamespace # ... other code ... view_result = bucket.view_query('ddoc-name', 'view-name', limit=10, namespace=DesignDocumentNamespace.DEVELOPMENT) for row in view_result.rows(): print(f'Found row: {row}')