API 参考
    正在准备搜索索引...

    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) {
    console.log(db.name);
    }
    索引

    构造函数

    方法

    • Add a user to the database

      参数

      • username: string

        The username for the new user

      • 可选passwordOrOptions: string | AddUserOptions

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

      • 可选options: AddUserOptions

        Optional settings for the command

      返回 Promise<Document>

    • Retrieve the server build information

      参数

      返回 Promise<Document>

    • Execute a command

      参数

      返回 Promise<Document>

    • List the available databases

      参数

      返回 Promise<ListDatabasesResult>

    • Ping the MongoDB server and retrieve results

      参数

      返回 Promise<Document>

    • Remove a user from a database

      参数

      返回 Promise<boolean>

    • Get ReplicaSet status

      参数

      返回 Promise<Document>

    • Retrieve the server build information

      参数

      返回 Promise<Document>

    • Retrieve this db's server status.

      参数

      返回 Promise<Document>

    • Validate an existing collection

      参数

      • collectionName: string

        The name of the collection to validate.

      • 可选options: ValidateCollectionOptions

        Optional settings for the command

      返回 Promise<Document>