An administrative class for managing Astra databases, including creating, listing, and deleting databases.

Shouldn't be instantiated directly; use DataAPIClient.admin to obtain an instance of this class.

To perform admin tasks on a per-database basis, see the AstraDbAdmin class.

Example

const client = new DataAPIClient('token');

// Create an admin instance with the default token
const admin1 = client.admin();

// Create an admin instance with a custom token
const admin2 = client.admin({ adminToken: 'stronger-token' });

const dbs = await admin1.listDatabases();
console.log(dbs);

See

  • DataAPIClient.admin
  • AstraDbAdmin

Hierarchy (view full)

Constructors

Properties

_db: Db
_httpClient: DevOpsAPIHttpClient

Accessors

  • get id(): string
  • Gets the ID of the Astra DB instance this object is managing.

    Returns string

    The ID of the Astra DB instance.

Methods

  • Creates a new, additional, namespace (aka keyspace) for this database.

    NB. this is a "long-running" operation. See AdminBlockingOptions about such blocking operations. The default polling interval is 1 second. Expect it to take roughly 8-10 seconds to complete.

    Parameters

    • namespace: string

      The name of the new namespace.

    • Optional options: AdminBlockingOptions

      The options for the blocking behavior of the operation.

    Returns Promise<void>

    A promise that resolves when the operation completes.

    Example

    await dbAdmin.createNamespace('my_other_keyspace1');

    // ['default_keyspace', 'my_other_keyspace1']
    console.log(await dbAdmin.listNamespaces());

    await dbAdmin.createNamespace('my_other_keyspace2', {
      blocking: false,
    });

    // Will not include 'my_other_keyspace2' until the operation completes
    console.log(await dbAdmin.listNamespaces());

    Remarks

    Note that if you choose not to block, the created namespace will not be able to be used until the operation completes, which is up to the caller to determine.

  • Gets the underlying Db object. The options for the db were set when the AstraDbAdmin instance, or whatever spawned it, was created.

    Returns Db

    The underlying Db object.

    Example

    const dbAdmin = client.admin().dbAdmin('<endpoint>', {
      namespace: 'my-namespace',
      useHttp2: false,
    });

    const db = dbAdmin.db();
    console.log(db.id);
  • Drops the database.

    NB. this is a long-running operation. See AdminBlockingOptions about such blocking operations. The default polling interval is 10 seconds. Expect it to take roughly 6-7 min to complete.

    The database info will still be accessible by ID, or by using the AstraAdmin.listDatabases method with the filter set to 'ALL' or 'TERMINATED'. However, all of its data will very much be lost.

    Parameters

    Returns Promise<void>

    A promise that resolves when the operation completes.

    Example

    const db = client.db('https://<db_id>-<region>.apps.astra.datastax.com');
    await db.admin().drop();

    Remarks

    Use with caution. Use a surge protector. Don't say I didn't warn you.

  • Drops a namespace (aka keyspace) from this database.

    NB. this is a "long-running" operation. See AdminBlockingOptions about such blocking operations. The default polling interval is 1 second. Expect it to take roughly 8-10 seconds to complete.

    Parameters

    • namespace: string

      The name of the namespace to drop.

    • Optional options: AdminBlockingOptions

      The options for the blocking behavior of the operation.

    Returns Promise<void>

    A promise that resolves when the operation completes.

    Example

    await dbAdmin.dropNamespace('my_other_keyspace1');

    // ['default_keyspace', 'my_other_keyspace2']
    console.log(await dbAdmin.listNamespaces());

    await dbAdmin.dropNamespace('my_other_keyspace2', {
      blocking: false,
    });

    // Will still include 'my_other_keyspace2' until the operation completes
    // ['default_keyspace', 'my_other_keyspace2']
    console.log(await dbAdmin.listNamespaces());

    Remarks

    Note that if you choose not to block, the namespace will still be able to be used until the operation completes, which is up to the caller to determine.

  • Fetches the complete information about the database, such as the database name, IDs, region, status, actions, and other metadata.

    The method issues a request to the DevOps API each time it is invoked, without caching mechanisms; this ensures up-to-date information for usages such as real-time collection validation by the application.

    Parameters

    Returns Promise<FullDatabaseInfo>

    A promise that resolves to the complete database information.

    Example

    const info = await dbAdmin.info();
    console.log(info.info.name, info.creationTime);
  • Lists the namespaces in the database.

    The first element in the returned array is the default namespace of the database, and the rest are additional namespaces in no particular order.

    Parameters

    Returns Promise<string[]>

    A promise that resolves to list of all the namespaces in the database.

    Example

    const namespaces = await dbAdmin.listNamespaces();

    // ['default_keyspace', 'my_other_keyspace']
    console.log(namespaces);