List collection names
Gets the names of the collections in a keyspace.
Method signature
-
Python
-
TypeScript
-
Java
-
curl
-
CLI
The following method belongs to the astrapy.Database
class.
list_collection_names(
*,
keyspace: str,
collection_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> list[str]
The following method belongs to the Db
class.
async listCollections(
options: {
nameOnly: true,
keyspace?: string,
timeout?: number | TimeoutDescriptor,
}
): string[]
The following method belongs to the com.datastax.astra.client.Database
class.
List<String> listCollectionNames()
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findCollections": {
"options": {
"explain": false
}
}
}'
astra db list-collections DATABASE_ID | cut -b 1-23
Result
-
Python
-
TypeScript
-
Java
-
curl
-
CLI
Returns the collection names as an unordered list of strings.
Example response:
['my_collection', 'my_vector_collection']
Returns a promise that resolves to the collection names as an unordered list of strings.
Example resolved response:
["quickstart_collection", "another_collection"]
Returns the collection names as a Stream of strings.
Returns the collection names as an unordered list of strings in the status.collections
field of the response.
Example response:
{
"status": {
"collections":[
"quickstart_collection",
"another_collection"
]
}
}
Prints the names of the collections.
Example response:
+---------------------+
| Name |
+---------------------+
| collection_simple |
| collection_vector |
| msp |
+---------------------+
Parameters
-
Python
-
TypeScript
-
Java
-
curl
-
CLI
Name | Type | Summary |
---|---|---|
|
|
the keyspace to be inspected. If not specified, the database’s working keyspace is used. |
|
|
A timeout, in milliseconds, for the underlying HTTP request.
If not provided, the |
Name | Type | Summary |
---|---|---|
|
Options regarding listing collections. |
Options (ListCollectionsOptions
):
Name | Type | Summary |
---|---|---|
|
If true, only the name of the collection is returned. Else, the full information for each collection is returned. Defaults to true. |
|
|
The keyspace to be inspected. If not specified, the database’s working keyspace is used. |
|
|
|
Optional. The timeout(s) to apply to this method.
You can specify Details about the
|
For details about each parameter, see the client reference.
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. |
|
|
If true, the response includes collection names and a brief explanation of metadata for each collection. If false or unset, the response includes only collection names. |
Name | Type | Summary |
---|---|---|
|
|
To get the |
Examples
The following examples demonstrate how to get collection names.
-
Python
-
TypeScript
-
Java
-
curl
-
CLI
database.list_collection_names()
Get the names of the collections in a specified keyspace of the database.
database.list_collection_names(keyspace="KEYSPACE_NAME")
Example:
from astrapy import DataAPIClient
client = DataAPIClient()
database = client.get_database("API_ENDPOINT", token="TOKEN")
database.list_collection_names()
# ['my_collection', 'my_vector_collection']
const collectionNames = await db.listCollections({ nameOnly: true });
Get the names of the collections in a specified keyspace of the database.
const collectionNames = await db.listCollections({ nameOnly: true, keyspace: 'KEYSPACE_NAME' });
Example:
import { DataAPIClient } from '@datastax/astra-db-ts';
// Get a new Db instance
const db = new DataAPIClient('TOKEN').db('API_ENDPOINT');
(async function () {
// Gets just names of all collections in db
const collections = await db.listCollections({ nameOnly: true });
for (const collectionName of collections) {
console.log(`Collection '${collectionName}' exists`);
}
})();
Example:
package com.datastax.astra.client.database;
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.collections.definition.CollectionDescriptor;
import com.datastax.astra.client.databases.Database;
import java.util.List;
public class ListCollections {
public static void main(String[] args) {
Database db = new DataAPIClient("TOKEN")
.getDatabase("API_ENDPOINT");
// Get collection Names
List<String> collectionNames = db.listCollectionNames();
// Get Collection information (with options)
List<CollectionDescriptor> collections = db.listCollections();
collections.stream().map(CollectionDescriptor::getOptions).forEach(System.out::println);
}
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findCollections": {
"options": {
"explain": false
}
}
}'
astra db list-collections DATABASE_ID | cut -b 1-23
Client reference
-
Python
-
TypeScript
-
Java
-
curl
-
CLI
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.
For more information, see the Astra CLI documentation.