Milvus
Zilliz
< Docs
  • Python

rename_collection()

This operation renames an existing collection.

Request Syntax

rename_collection(
    old_name: str,
    new_name: str,
    target_db: Optional[str] = "",
    timeout: Optional[float] = None,
    **kwargs,
) -> None

PARAMETERS:

  • old_name (str) -

    [REQUIRED]

    The name of an existing collection.

    Setting this to a non-existing collection results in a MilvusException.

  • new_name (str) -

    [REQUIRED]

    The name of the target collection after this operation.

    Setting this to the value of old_name results in a MilvusException.

  • target_db (Optional[str]) -

    The name of the target database to which the collection will be moved. Defaults to an empty string, which means the collection stays in the current database.

  • timeout (float | None) -

    The timeout duration for this operation. Setting this to None indicates that this operation timeouts when any response arrives or any error occurs.

RETURN TYPE:

NoneType

RETURNS:

None

EXCEPTIONS:

  • MilvusException

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

Examples

from pymilvus import MilvusClient

client = MilvusClient(
    uri="http://localhost:19530",
    token="root:Milvus"
)

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

# Rename the collection
client.rename_collection(
    old_name="test_collection",
    new_name="test_collection_renamed"
)

# Move collection to another database
client.rename_collection(
    old_name="test_collection_renamed",
    new_name="test_collection",
    target_db="my_database"
)