Collections
- class couchbase.management.collections.CollectionManager(impl: CollectionMgmtInterface)
Performs management operations on a bucket’s scopes and collections.
- create_collection(collection: CollectionSpec, options: CreateCollectionOptions | None = None, **kwargs: Unpack[CreateCollectionOptionsKwargs]) None
- create_collection(scope_name: str, collection_name: str, settings: CreateCollectionSettings | None = None, options: CreateCollectionOptions | None = None, **kwargs: Unpack[CreateCollectionOptionsKwargs]) None
Creates a new collection in a specified scope.
Deprecated since version 4.1.9: The overload that takes a
CollectionSpecis deprecated; passscope_nameandcollection_nameinstead.- Parameters:
scope_name (str) – The name of the scope the collection will be created in.
collection_name (str) – The name of the collection to be created
settings (
CreateCollectionSettings, optional) – Settings to apply for the collectionoptions (
CreateCollectionOptions) – Optional parameters for this operation.**kwargs – keyword arguments that can be used as optional parameters for this operation.
- Raises:
CollectionAlreadyExistsException – If the collection already exists.
ScopeNotFoundException – If the scope does not exist.
- create_scope(scope_name: str, options: CreateScopeOptions | None = None, **kwargs: Unpack[CreateScopeOptionsKwargs]) None
Creates a new scope.
- Parameters:
scope_name (str) – The name of the scope.
options (
CreateScopeOptions) – Optional parameters for this operation.**kwargs – keyword arguments that can be used as optional parameters for this operation.
- Raises:
ScopeAlreadyExistsException – If the scope already exists.
- drop_collection(collection: CollectionSpec, options: DropCollectionOptions | None = None, **kwargs: Unpack[DropCollectionOptionsKwargs]) None
- drop_collection(scope_name: str, collection_name: str, options: DropCollectionOptions | None = None, **kwargs: Unpack[DropCollectionOptionsKwargs]) None
Drops a collection from the specified scope.
Deprecated since version 4.1.9: The overload that takes a
CollectionSpecis deprecated; passscope_nameandcollection_nameinstead.- Parameters:
scope_name (str) – The name of the scope the collection is in.
collection_name (str) – The name of the collection to be dropped
options (
DropCollectionOptions) – Optional parameters for this operation.**kwargs – keyword arguments that can be used as optional parameters for this operation.
- Raises:
CollectionNotFoundException – If the collection does not exist.
- drop_scope(scope_name: str, options: DropScopeOptions | None = None, **kwargs: Unpack[DropScopeOptionsKwargs]) None
Drops an existing scope.
- Parameters:
scope_name (str) – The name of the scope.
options (
DropScopeOptions) – Optional parameters for this operation.**kwargs – keyword arguments that can be used as optional parameters for this operation.
- Raises:
ScopeNotFoundException – If the scope does not exist.
- get_all_scopes(options: GetAllScopesOptions | None = None, **kwargs: Unpack[GetAllScopesOptionsKwargs]) Iterable[ScopeSpec]
Returns all configured scopes along with their collections.
- Parameters:
options (
GetAllScopesOptions) – Optional parameters for this operation.**kwargs – keyword arguments that can be used as optional parameters for this operation.
- Returns:
A list of all configured scopes.
- Return type:
Iterable[
ScopeSpec]
- update_collection(scope_name: str, collection_name: str, settings: UpdateCollectionSettings, options: UpdateCollectionOptions | None = None, **kwargs: Unpack[UpdateCollectionOptionsKwargs]) None
Updates a collection in a specified scope.
- Parameters:
scope_name (str) – The name of the scope the collection is in.
collection_name (str) – The name of the collection that will be updated
settings (
UpdateCollectionSettings) – Settings to apply for the collectionoptions (
UpdateCollectionOptions) – Optional parameters for this operation.**kwargs – keyword arguments that can be used as optional parameters for this operation.
- Raises:
CollectionNotFoundException – If the collection does not exist.
ScopeNotFoundException – If the scope does not exist.
- class couchbase.management.collections.CollectionSpec(collection_name: str, scope_name: str = '_default', max_expiry: timedelta | None = None, max_ttl: timedelta | None = None, history: bool | None = None)
A collection, as
CollectionManager.get_all_scopes()describes it.- Parameters:
collection_name (str) – The name of the collection.
scope_name (str, optional) – The name of the collection’s scope. Defaults to
_default.max_expiry (timedelta, optional) – The longest expiry a document in the collection can have.
max_ttl (timedelta, optional) – DEPRECATED Use
max_expiry.history (bool, optional) – Whether the collection keeps a change history.
- property history: bool | None
Whether the collection keeps a change history.
Nonemeans the collection follows the bucket’s setting.
- property max_ttl: timedelta | None
The longest expiry a document in the collection can have.
Deprecated since version 4.3.5: Use
max_expiryinstead.
- class couchbase.management.collections.CreateCollectionSettings(max_expiry: timedelta | None = None, history: bool | None = None)
Specifies settings for a collection that will be created.
- class couchbase.management.collections.ScopeSpec(name: str, collections: Iterable[CollectionSpec])
A scope and its collections, as
CollectionManager.get_all_scopes()describes them.- Parameters:
name (str) – The name of the scope.
collections (Iterable[
CollectionSpec]) – The scope’s collections.
- property collections: Iterable[CollectionSpec]
The scope’s collections.
- class couchbase.management.collections.UpdateCollectionSettings(max_expiry: timedelta | None = None, history: bool | None = None)
Specifies settings for a collection that will be updated.