Skip to main content

AddCollectionField()

This operation adds a nullable field to an existing collection by altering the collection schema on the server, then evicts the client collection cache for the collection.

go
func (c *Client) AddCollectionField(ctx context.Context, opt AddCollectionFieldOption, callOpts ...grpc.CallOption) error

Request Syntax​

Creates the request for AddCollectionField().

go
option := milvusclient.NewAddCollectionFieldOption(collectionName, field)

err := client.AddCollectionField(ctx, option)

PARAMETERS:

  • collectionName (string) -

    [REQUIRED]

    The name of the collection to which the field is added.

  • field (*entity.Field) -

    [REQUIRED]

    The field definition to add. Vector fields must be nullable.

BUILDER METHODS:

  • NewAddCollectionFieldOption(collectionName string, field *entity.Field)

    Creates the request for AddCollectionField().

RETURN TYPE:

error

RETURNS:

Returns nil after the operation succeeds. Returns an error when client-side validation or the RPC fails.

ERROR HANDLING:

  • error

    Client-side validation or the RPC fails. Check the returned error for failure details.

Example​

Demonstrates AddCollectionField usage.

go
import (
"context"

"github.com/milvus-io/milvus/client/v3/entity"
"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)

field := entity.NewField().
WithName("new_field").
WithDataType(entity.FieldTypeInt64).
WithNullable(true)

err = cli.AddCollectionField(ctx, milvusclient.NewAddCollectionFieldOption("books", field))
if err != nil {
// handle error
}
Minimum SDK versionv3.0.x
Was this page helpful?