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


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) {


  • Admin


  • 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.


    Returns Promise<Document>

  • Remove a user from a database


    • username: string

      The username to remove

    • Optional options: CommandOperationOptions

      Optional settings for the command

    Returns Promise<boolean>

  • Validate an existing collection


    • collectionName: string

      The name of the collection to validate.

    • options: ValidateCollectionOptions = {}

      Optional settings for the command

    Returns Promise<Document>

Generated using TypeDoc