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:
| Placeholder | Description |
|---|---|
<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:
| Method | Return type | Description | Example |
|---|---|---|---|
getCode() | int | Status code. For details, see Status codes. | 0 |
getMessage() | String | Response message. | success |
getRequestId() | String | Unique request ID. | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
getOutput() | List<String> | Collection names in the cluster. | ["my_collection1", "my_collection2"] |
isSuccess() | Boolean | Whether the operation succeeded. | true |
该文章对您有帮助吗?