List collections

更新时间:
复制 MD 格式

List all collection names in a DashVector cluster using the Java SDK.

Prerequisites

Before you begin, make sure you have:

API signature

// DashVectorClient
public Response<List<String>> list();

The list() method takes no parameters and returns a Response<List<String>> containing the names of all collections in the cluster.

Example

Replace the placeholders before running the code:

PlaceholderDescription
<your-api-key>API key for your DashVector cluster
<your-cluster-endpoint>Endpoint of your DashVector cluster
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;

public class Main {
    public static void main(String[] args) throws DashVectorException {
        // Initialize the client
        DashVectorClient client = new DashVectorClient("<your-api-key>", "<your-cluster-endpoint>");

        // List all collections
        Response<List<String>> response = client.list();

        System.out.println(response);
    }
}

Expected output:

{
    "code": 0,
    "message": "",
    "requestId": "5de1a75e-2996-4496-a284-9b958dfdad53",
    "output": [
        "simple",
        "quickstart"
    ]
}

Response parameters

list() returns a Response<List<String>> object. The following methods are available:

MethodReturn typeDescriptionExample
getCode()intStatus code. For details, see Status codes.0
getMessage()StringResponse message.success
getRequestId()StringUnique request ID.19215409-ea66-4db9-8764-26ce2eb5bb99
getOutput()List<String>Collection names in the cluster.["my_collection1", "my_collection2"]
isSuccess()BooleanWhether the operation succeeded.true