Skip to main content

has_collection()

This operation checks whether a specific collection exists.

Notes

This method applies to dedicated serving clusters and on-demand compute.

  • For a collection in a serving cluster, please create MilvusClient with the cluster endpoint.

    • Free & Serverless

      https://{cluster-id}.serverless.{region}.vectordb.zillizcloud.com

    • Dedicated

      https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530

  • For a collection in on-demand compute, create MilvusClient with the project endpoints.

    https://{project-id}.{region}.api.zillizcloud.com

Request Syntax​

python
has_collection(
collection_name: str,
timeout: Optional[float] = None
) -> Bool

PARAMETERS:

  • collection_name (str) -

    [REQUIRED]

    The name of a collection.

  • timeout (float | None) -

    The timeout duration for this operation.

    Setting this to None indicates that this operation timeouts when any response returns or error occurs.

RETURN TYPE:

bool

RETURNS:

A boolean value indicating whether the specified collection exists.

EXCEPTIONS:

  • MilvusException

    This exception will be raised when any error occurs during this operation.

Examples​

python
from pymilvus import MilvusClient

# 1. Set up a milvus client
client = MilvusClient(
uri="https://inxx-xxxxxxxxxxxx.api.gcp-us-west1.zillizcloud.com:19530",
token="user:password"
)

# 2. Create a collection
client.create_collection(collection_name="test_collection", dimension=5)

# 3. Check whether a collection named `test_collection` exists
client.has_collection(collection_name="test_collection")

# True

# 4. Check whether a collection named `test_collection_2` exists
client.has_collection(collection_name="test_collection_2")

# False
Minimum SDK versionv2.3.x