Skip to main content

truncateCollection()

This operation removes all data from a collection but retains the collection schema and structure.

javascript
await milvusClient.truncateCollection(data: DropCollectionReq)
📘Notes
  • Irreversible operation

Truncating a collection permanently removes all data.

  • Schema preserved

The collection structure, fields, indexes, and properties remain intact.

Request Syntax​

javascript
truncateCollection({
db_name?: string,
collection_name: string,
timeout?: number
})

PARAMETERS:

  • db_name (string) -

    The name of the database containing the collection.

  • collection_name (string) -

    [REQUIRED]

    The name of the target collection.

  • timeout (number) -

    RPC timeout in milliseconds.

RETURNS:

Promise<{ status: ResStatus }>

This method returns a promise that resolves to an object containing a ResStatus.

javascript
{
status: ResStatus
}

PARAMETERS:

  • status (ResStatus) -

    A ResStatus object.

    • code (number) -

      A code that indicates the operation result. It remains 0 if this operation succeeds.

    • error_code (string | number) -

      An error code that indicates an occurred error. It remains Success if this operation succeeds.

    • reason (string) -

      The reason that indicates the reason for the reported error. It remains an empty string if this operation succeeds.

EXCEPTIONS:

  • Error

    This exception is raised when any error occurs during this operation.

Examples​

Basic usage​

javascript
import { MilvusClient } from '@zilliz/milvus2-sdk-node';

const milvusClient = new MilvusClient({
address: 'YOUR_CLUSTER_ENDPOINT',
token: 'YOUR_CLUSTER_TOKEN',
});

// Truncate collection
const res = await milvusClient.truncateCollection({
collection_name: 'my_collection',
});

console.log(res);
// Output: { status: { error_code: 'Success', reason: '' } }

With database specified​

javascript
const res = await milvusClient.truncateCollection({
db_name: 'my_database',
collection_name: 'my_collection',
});
Minimum SDK versionv2.6.x
Was this page helpful?