Class Admin

The Admin class is an internal class that allows convenient access to the admin functionality and commands for MongoDB.

ADMIN Cannot directly be instantiated

Example

import { MongoClient } from 'mongodb';

const client = new MongoClient('mongodb://localhost:27017');
const admin = client.db().admin();
const dbInfo = await admin.listDatabases();
for (const db of dbInfo.databases) {
console.log(db.name);
}

Hierarchy

  • Admin

Methods

  • Execute a command

    The driver will ensure the following fields are attached to the command sent to the server:

    • lsid - sourced from an implicit session or options.session
    • $readPreference - defaults to primary or can be configured by options.readPreference
    • $db - sourced from the name of this database

    If the client has a serverApi setting:

    • apiVersion
    • apiStrict
    • apiDeprecationErrors

    When in a transaction:

    • readConcern - sourced from readConcern set on the TransactionOptions
    • writeConcern - sourced from writeConcern set on the TransactionOptions

    Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.

    Parameters

    Returns Promise<Document>

  • Remove a user from a database

    Parameters

    • username: string

      The username to remove

    • Optional options: CommandOperationOptions

      Optional settings for the command

    Returns Promise<boolean>

  • Validate an existing collection

    Parameters

    • collectionName: string

      The name of the collection to validate.

    • options: ValidateCollectionOptions = {}

      Optional settings for the command

    Returns Promise<Document>

Generated using TypeDoc