Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Methods

  • Add a user to the database

    Parameters

    • username: string

      The username for the new user

    • Optional passwordOrOptions: string | AddUserOptions

      An optional password for the new user, or the options for the command

    • Optional options: AddUserOptions

      Optional settings for the command

    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>

Generated using TypeDoc