List collection names
Gets the names of the collections in a keyspace.
Method signature
-
Python
-
TypeScript
-
Java
-
curl
-
CLI
database.list_collection_names(
*,
keyspace: str,
max_time_ms: int,
) -> list[str]
database.listCollections(
options: {
nameOnly?: boolean,
keyspace?: string,
maxTimeMS?: number,
}
): Promise<string[]>
Stream<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:
["quickstart_collection", "another_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. |
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. |
|
|
Maximum time in milliseconds the client should wait for the operation to complete. |
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("TOKEN")
database = client.get_database("API_ENDPOINT")
database.list_collection_names()
# ['a_collection', 'another_col']
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`);
}
})();
// Given `db` Database object, list all collections
Stream<String> collection = listCollectionsNames();
Example:
package com.datastax.astra.client.database;
import com.datastax.astra.client.Database;
import com.datastax.astra.client.model.CollectionInfo;
import java.util.stream.Stream;
public class ListCollections {
public static void main(String[] args) {
Database db = new Database("TOKEN", "API_ENDPOINT");
// Get collection Names
Stream<String> collectionNames = db.listCollectionNames();
// Get Collection information (with options)
Stream<CollectionInfo> collections = db.listCollections();
collections.map(CollectionInfo::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.