AddCollectionField()
クライアント側でフィールドオプションを検証した後、既存のコレクションに nullable フィールドを追加します。
go
func (c *Client) AddCollectionField(ctx context.Context, opt AddCollectionFieldOption, callOpts ...grpc.CallOption) error
パラメータ:
-
collectionName (string) -
[必須]
フィールドを追加するコレクションの名前です。
-
field (*entity.Field) -
[必須]
追加するフィールド定義です。ベクトルフィールドは nullable である必要があります。
戻り値の型:
error
戻り値:
フィールドの追加後に nil を返します。クライアント側の検証または RPC が失敗した場合はエラーを返します。
エラーハンドリング:
-
error
検証、リクエストの構築、または RPC が失敗します。失敗の詳細は、返された error を確認してください。
例
AddCollectionField() の使用方法を示します。
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
}