Find all databases (Go)
Lists all databases.
|
You need an application token with permission to create and configure databases, such as the Organization Administrator role. For more information, see Get endpoint and token. |
Result
Returns a slice of FullAstraDatabaseInfo structs that each describe a database.
Signature
Use the ListDatabases method, which belongs to the AstraAdmin type.
func (a *AstraAdmin) ListDatabases(
ctx context.Context,
opts ...options.ListDatabasesOption
) ([]FullAstraDatabaseInfo, error)
Parameters
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional. Filters the returned databases by status. Some database status are short-lived or do not apply to Astra DB Serverless databases. Default: |
|
Optional. Filters the returned databases by cloud provider. Default: |
|
Optional. The number of results per page. Maximum: 100 Default: 25 |
|
Optional. Pass the database ID of the last item on the previous page to get the next page. |
|
Optional. General API options for this operation, including the timeout. |
Examples
The following examples demonstrate how to list databases.
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()
client := astra.NewClient(
options.API().SetToken("APPLICATION_TOKEN"),
)
admin, err := client.Admin()
if err != nil {
log.Fatal(err)
}
databases, err := admin.ListDatabases(ctx)
if err != nil {
log.Fatal(err)
}
output, err := json.Marshal(databases)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(output))
}
Errors
For a full list of Data API error codes and their corresponding messages, see Data API errors and error codes.
For more information about how the client handles underlying Data API errors, see Go client error handling.
Client reference
For more information, see the client reference.