メインコンテンツまでスキップ

AddCollectionField()

This operation adds a new scalar field to an existing collection without recreating it. The field becomes available almost immediately with minimal delay due to internal schema synchronization.

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

Request Parameters

Parameter

Description

Type

ctx

Context for the current call to work.

context.Context

option

Optional parameters of the methods.

AddCollectionFieldOption

callOpts

Optional parameters for calling the methods.

grpc.CallOption

AddCollectionFieldOption

This is an interface type. The addCollectionFieldOption struct type implements this interface. You can use NewAddCollectionFieldOption() to get its concrete implementation.

func NewAddCollectionFieldOption(collectionName string, field *entity.Field) *addCollectionFieldOption

Parameter

Description

Type

collectionName

Name of the target collection.

string

field

The field to add.

*entity.Field

Return

Null

Example

package main

import (
"context"
"log"

"github.com/milvus-io/milvus/client/v2/entity"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

milvusAddr := "YOUR_CLUSTER_ENDPOINT"

cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
})
if err != nil {
log.Fatal("failed to connect to milvus server: ", err.Error())
}

defer cli.Close(ctx)

// the field to add
// must be nullable for now
newField := entity.NewField().WithName("new_field").WithDataType(entity.FieldTypeInt64).WithNullable(true)

err = cli.AddCollectionField(ctx, milvusclient.NewAddCollectionFieldOption("customized_setup_2", newField))
if err != nil {
// handle error
}
}