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
-
Java
-
curl
Returns a list of CollectionDescriptor
objects that describe each collection.
Example response:
[
CollectionDescriptor(
name='my_collection',
definition=CollectionDefinition(
indexing={'allow': ['country', 'city']}
),
raw_descriptor=...
),
CollectionDescriptor(
name='my_vector_collection',
definition=CollectionDefinition(
vector=CollectionVectorOptions(
dimension=3,
metric='dot_product',
source_model='other',
service=None
),
),
raw_descriptor=...
)
]
Returns a promise that resolves to an array of CollectionDescriptor
objects that describe each collection.
Returns a List<CollectionDescriptor>
, where each CollectionDescriptor
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" : 5,
"metric" : "cosine"
}
}
},
{
"name" : "book_collection",
"options" : {
"defaultId": {
"type": "objectId"
},
"vector" : {
"dimension" : 5,
"metric" : "cosine"
}
}
}
]
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
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 keyspace when instantiating the Default: The database’s working keyspace. |
|
|
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 keyspace when instantiating the Default: The database’s working keyspace. |
|
|
|
Optional. The timeout(s) to apply to this method.
You can specify Details about the
|
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. |
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 |
---|---|---|
|
|
The Data API command to find all collections in the specified database and keyspace. It acts as a container for all the attributes and settings required to find collections. |
|
|
Must be |
Examples
The following examples demonstrate how to get collection metadata.
-
Python
-
TypeScript
-
Java
-
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"),
)
# List collections
database.list_collections(keyspace="KEYSPACE_NAME")
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"),
});
// List collections
(async function () {
await database.listCollections({
nameOnly: false,
keyspace: "KEYSPACE_NAME",
});
})();
import com.datastax.astra.client.DataAPIClient;
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
DataAPIClient client = DataAPIClients.clientHCD("USERNAME", "PASSWORD");
Database database = client.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");
// List collections
List<CollectionDescriptor> collectionMetadata = database.listCollections();
collectionMetadata.stream().map(CollectionDescriptor::getOptions).forEach(System.out::println);
}
}
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
-
Java
-
curl
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.