查看 Collection
您既可以查看当前连接的数据库中已创建的 Collection 名称列表,也可以针对某个 Collection 了解其详细情况。
查看 Collection 列表
如下示例演示了如何查看当前连接的数据库中已创建的 Collection 名称列表。
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient, DataType
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
res = client.list_collections()
print(res)
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.collection.response.ListCollectionsResp;
ConnectConfig connectConfig = ConnectConfig.builder()
.uri("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.build();
MilvusClientV2 client = new MilvusClientV2(connectConfig);
ListCollectionsResp resp = client.listCollections();
System.out.println(resp.getCollectionNames());
import { MilvusClient } from '@zilliz/milvus2-sdk-node';
const client = new MilvusClient({
address: 'localhost:19530',
token: 'YOUR_CLUSTER_TOKEN'
});
const collections = await client.listCollections();
console.log(collections);
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
milvusAddr := "YOUR_CLUSTER_ENDPOINT"
token := "YOUR_CLUSTER_TOKEN"
cli, err := client.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
APIKey: token,
})
if err != nil {
log.Fatal("failed to connect to milvus server: ", err.Error())
}
defer cli.Close(ctx)
collectionNames, err := cli.ListCollections(ctx, milvusclient.NewListCollectionOption())
if err != nil {
// handle error
}
fmt.Println(collectionNames)
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/list" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{}
}'
如果您已经创建了名为 quick_setup
的 Collection,运行上述示例的结果如下:
["quick_setup"]
查看 Collection 详情
您也可以根据需要查看某个 Collection 的详细情况。如下示例代码中假设您已经创建了名为 quick_setup 的 Collection。
- Python
- Java
- NodeJS
- Go
- cURL
res = client.describe_collection(
collection_name="quick_setup"
)
print(res)
import io.milvus.v2.service.collection.request.DescribeCollectionReq;
import io.milvus.v2.service.collection.response.DescribeCollectionResp;
DescribeCollectionReq request = DescribeCollectionReq.builder()
.collectionName("quick_setup")
.build();
DescribeCollectionResp resp = client.describeCollection(request);
System.out.println(resp);
const res = await client.describeCollection({
collection_name: "quick_setup"
});
console.log(res);
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
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)
collection, err := cli.DescribeCollection(ctx, milvusclient.NewDescribeCollectionOption("quick_setup"))
if err != nil {
// handle error
}
fmt.Println(collection)
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/collections/describe" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "quick_setup"
}'
如果您已经创建了名为 quick_setup
的 Collection,运行上述示例的结果如下:
// TO BE ADDED