List collection names
Gets the names of 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
-
C#
-
curl
Returns the collection names as an unordered list of strings.
Returns a promise that resolves to the collection names as an unordered list of strings.
Returns the collection names as a Stream of strings.
Returns the collection names as an unordered list 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"
]
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
C#
-
curl
Use the list_collection_names method, which belongs to the astrapy.Database class.
Method signature
list_collection_names(
*,
keyspace: str,
collection_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> list[str]
| Name | Type | Summary |
|---|---|---|
|
|
Optional if you specified a keyspace when instantiating the Default: The database’s working keyspace. |
|
|
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: true,
keyspace?: string,
timeout?: number | TimeoutDescriptor,
}
): string[]
| Name | Type | Summary |
|---|---|---|
|
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 listCollectionNames method, which belongs to the com.datastax.astra.client.Database class.
Method signature
List<String> listCollectionNames()
List<String> listCollectionNames(ListCollectionOptions options)
| Name | Type | Summary |
|---|---|---|
|
Optional. The options for this operation, including the keyspace and timeouts. |
Use the ListCollectionNamesAsync method, which belongs to the Database class.
You can also use ListCollectionNames, which is the synchronous version of the method.
Method signature
public Task<List<string>> ListCollectionNamesAsync(
ListCollectionNamesOptions options = null
);
| Name | Type | Summary |
|---|---|---|
|
Optional.
General API options for this operation, including the keyspace and timeout.
Keyspace is required unless you specified a 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": false
}
}
}'
| Name | Type | Summary |
|---|---|---|
|
|
Must be |
Examples
The following examples demonstrate how to get collection names.
-
Python
-
TypeScript
-
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"),
)
# List collections
database.list_collection_names(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: true,
keyspace: "KEYSPACE_NAME",
});
})();
import com.datastax.astra.client.DataAPIClients;
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<String> collectionNames = database.listCollectionNames();
}
}
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 names = await database.ListCollectionNamesAsync();
Console.WriteLine(JsonSerializer.Serialize(names));
}
}
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findCollections": {
"options": {
"explain": false
}
}
}'
Client reference
-
Python
-
TypeScript
-
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.
Client reference documentation is not applicable for HTTP.