TruncateCollection
This operation removes all data from a collection while keeping its schema.
go
func (c *Client) TruncateCollection(ctx context.Context, option TruncateCollectionOption, callOptions ...grpc.CallOption) error
Request Syntax
Creates the request for TruncateCollection().
go
option := milvusclient.NewTruncateCollectionOption(collectionName)
err := client.TruncateCollection(ctx, option)
PARAMETERS:
-
name (string) -
[REQUIRED]
The name of the collection to create.
BUILDER METHODS:
-
NewTruncateCollectionOption(name string)Creates options to truncate a collection.
namespecifies the collection to truncate.
RETURN TYPE:
error
RETURNS:
Returns nil after the collection is truncated. Returns an error if the operation fails.
ERROR HANDLING:
-
error
The operation fails. Request construction or the RPC fails. Check
err != nilfor failure details.
Example
Demonstrates TruncateCollection() usage.
go
import (
"context"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{Address: "YOUR_CLUSTER_ENDPOINT"})
if err != nil {
// handle error
}
defer cli.Close(ctx)
err = cli.TruncateCollection(ctx, milvusclient.NewTruncateCollectionOption("books"))
if err != nil {
// handle error
}