List collection metadata
Gets information about the collections in a keyspace.
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
Returns a list of CollectionDescriptor objects that describe each collection.
Returns a promise that resolves to an array of CollectionDescriptor objects that describe each collection.
Returns a slice of CollectionDescriptor structs that describe each collection.
Returns a List<CollectionDescriptor>, where each CollectionDescriptor object describes a collection.
Returns IEnumerable<CollectionInfo>, where each CollectionInfo object describes a collection.
The status.collections field in the response describes each collection.
Example response:
{
"status": {
"collections": [
{
"name": "student_collection",
"options": {
"defaultId": {
"type": "objectId"
},
"vector": {
"dimension": 1024,
"metric": "cosine"
}
},
"lexical": {
"enabled": true,
"analyzer": "standard"
},
"rerank": {
"enabled": true,
"service": {
"provider": "nvidia",
"modelName": "nvidia/llama-3.2-nv-rerankqa-1b-v2"
}
}
},
{
"name": "book_collection",
"options": {
"vector": {
"dimension": 1024,
"metric": "cosine",
"sourceModel": "other",
"service": {
"provider": "nvidia",
"modelName": "NV-Embed-QA"
}
},
"lexical": {
"enabled": false
},
"rerank": {
"enabled": false
}
}
}
]
}
}
Parameters
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
Use the list_collections method, which belongs to the astrapy.Database class.
Method signature
list_collections(
*,
keyspace: str,
collection_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> list[CollectionDescriptor]
| Name | Type | Summary |
|---|---|---|
|
|
Optional if you specified a working keyspace when you created the Default: The working keyspace set when you created the |
|
|
Optional.
A timeout, in milliseconds, for the underlying HTTP request.
If not provided, the |
Use the listCollections method, which belongs to the Db class.
Method signature
async listCollections(
options: {
nameOnly?: false,
keyspace?: string,
timeout?: number | TimeoutDescriptor,
}
): CollectionDescriptor[]
| Name | Type | Summary |
|---|---|---|
|
Optional.
The options for this operation.
See Properties of |
| Name | Type | Summary |
|---|---|---|
|
|
Must be |
|
|
Optional if you specified a working keyspace when you created the Default: The working keyspace set when you created the |
|
|
Optional. The timeout(s) to apply to this method.
You can specify For more information about the |
Use the ListCollections method, which belongs to the Db type.
Method signature
func (d *Db) ListCollections(
ctx context.Context,
opts ...options.ListCollectionsOption
) ([]results.CollectionDescriptor, error)
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional if you specified a working keyspace when you created the Default: The working keyspace set when you created the |
|
Optional. General API options for this operation, including the timeout. |
Use the listCollections method, which belongs to the com.datastax.astra.client.Database class.
Method signature
List<CollectionDescriptor> listCollections()
List<CollectionDescriptor> listCollections(ListCollectionOptions options)
| Name | Type | Summary |
|---|---|---|
|
Optional.
The options for this operation, including the keyspace and timeouts.
Keyspace is required unless you specified a working keyspace when instantiating the |
Use the ListCollectionsAsync method, which belongs to the Database class.
You can also use ListCollections, which is the synchronous version of the method.
Method signature
public Task<IEnumerable<CollectionInfo>> ListCollectionsAsync(
ListCollectionsOptions options = null
);
| Name | Type | Summary |
|---|---|---|
|
Optional.
General API options for this operation, including the keyspace and timeout.
Keyspace is required unless you specified a working keyspace when instantiating the |
Use the findCollections command.
Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findCollections": {
"options": {
"explain": true
}
}
}'
| Name | Type | Summary |
|---|---|---|
|
|
Must be |
Examples
The following examples demonstrate how to get collection metadata.
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment
# Get a database
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
"API_ENDPOINT",
token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
keyspace="KEYSPACE_NAME",
)
# List collections
database.list_collections()
import {
DataAPIClient,
UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";
// Get a database
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
keyspace: "KEYSPACE_NAME",
});
// List collections
(async function () {
await database.listCollections({
nameOnly: false,
});
})();
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get a database
client := astra.NewClient(
options.API().SetEnvironment(options.EnvironmentHCD),
)
database := client.Database(
"API_ENDPOINT",
options.API().
SetUsernamePasswordTokenProvider(
"USERNAME",
"PASSWORD",
).
SetKeyspace("KEYSPACE_NAME"),
)
// List collections
collections, err := database.ListCollections(ctx)
if err != nil {
log.Fatal(err)
}
output, err := json.Marshal(collections)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(output))
}
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.collections.definition.CollectionDescriptor;
import com.datastax.astra.client.databases.Database;
import java.util.List;
public class Example {
public static void main(String[] args) {
// Get a database
Database database =
DataAPIClients.clientHCD("USERNAME", "PASSWORD")
.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");
// List collections
List<CollectionDescriptor> collectionMetadata = database.listCollections();
collectionMetadata.stream().map(CollectionDescriptor::getOptions).forEach(System.out::println);
}
}
using System.Text.Json;
using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;
namespace Examples;
public class Program
{
static async Task Main()
{
// Get a database
var client = new DataAPIClient(
new CommandOptions() { Destination = DataAPIDestination.HCD }
);
var database = client.GetDatabase(
"API_ENDPOINT",
DataAPIClient.UsernamePasswordTokenProvider(
"USERNAME",
"PASSWORD"
),
"KEYSPACE_NAME"
);
// List collections
var collectionMetadata = await database.ListCollectionsAsync();
Console.WriteLine(JsonSerializer.Serialize(collectionMetadata));
}
}
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findCollections": {
"options": {
"explain": true
}
}
}'
Client reference
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.