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

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

Note that the environment parameter MUST match the one used in the DataAPIClient options.

Example

const client = new DataAPIClient('*TOKEN*');

// Create an admin instance through a Db
const db = client.db('*ENDPOINT*');
const dbAdmin1 = db.admin({ environment: 'dse' );
const dbAdmin2 = db.admin({ environment: 'dse', adminToken: 'stronger-token' });

await admin1.createNamespace({
  replication: {
  class: 'NetworkTopologyStrategy',
  datacenter1: 3,
  datacenter2: 2,
  },
});

const namespaces = await admin1.listNamespaces();
console.log(namespaces);

See

  • Db.admin
  • AstraDbAdmin.dbAdmin

Hierarchy (view full)

Constructors

Properties

#db: Db
#httpClient: DataAPIHttpClient

Accessors

Methods

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

    NB. The operation will always wait for the operation to complete, regardless of the AdminBlockingOptions. Expect it to take roughly 8-10 seconds.

    Parameters

    • namespace: string

      The name of the new namespace.

    • Optional options: LocalCreateNamespaceOptions

      The options for the timeout & replication behavior of the operation.

    Returns Promise<void>

    A promise that resolves when the operation completes.

    Example

    await dbAdmin.createNamespace('my_namespace');

    await dbAdmin.createNamespace('my_namespace', {
      replication: {
      class: 'SimpleStrategy',
      replicatonFactor: 3,
      },
    });

    await dbAdmin.createNamespace('my_namespace', {
      replication: {
      class: 'NetworkTopologyStrategy',
      datacenter1: 3,
      datacenter2: 2,
      },
    });
  • Gets the underlying Db object. The options for the db were set when the DataAPIDbAdmin 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.namespace);
  • Drops a namespace (aka keyspace) from this database.

    NB. The operation will always wait for the operation to complete, regardless of the AdminBlockingOptions. Expect it to take roughly 8-10 seconds.

    Parameters

    • namespace: string

      The name of the namespace to drop.

    • Optional options: AdminBlockingOptions

      The options for the timeout of the operation.

    Returns Promise<void>

    A promise that resolves when the operation completes.

    Example

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

    await dbAdmin.dropNamespace('my_other_keyspace');

    // ['default_keyspace', 'my_other_keyspace']
    console.log(await dbAdmin.listNamespaces());
  • Returns detailed information about the availability and usage of the vectorize embedding providers available on the current database (may vary based on cloud provider & region).

    Parameters

    • Optional options: WithTimeout

      The options for the timeout of the operation.

    Returns Promise<FindEmbeddingProvidersResult>

    The available embedding providers.

    Example

    const { embeddingProviders } = await dbAdmin.findEmbeddingProviders();

    // ['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002']
    console.log(embeddingProviders['openai'].models.map(m => m.name));
  • 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);