Class Admin

The Admin class is an internal class that allows convenient access to the admin functionality and commands for MongoDB.Admin类是一个内部类,它允许方便地访问MongoDB的管理功能和命令。

ADMIN Cannot directly be instantiatedADMIN不能直接实例化

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

  • Retrieve the server build information检索服务器内部版本信息

    Parameters

    Returns Promise<Document>

  • 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来源于隐含会话或options.session
    • $readPreference - defaults to primary or can be configured by options.readPreference默认为primary,或者可以通过options.readPreference进行配置
    • $db - sourced from the name of this database来源于此数据库的名称

    If the client has a serverApi setting:如果客户端具有serverApi设置:

    • apiVersion
    • apiStrict
    • apiDeprecationErrors

    When in a transaction:在事务中:

    • readConcern - sourced from readConcern set on the TransactionOptions来源于TransactionOptions上设置的readConcern
    • writeConcern - sourced from writeConcern set on the TransactionOptions来源于TransactionOptions上设置的writeConcern

    Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.将上述任何字段附加到命令将不会产生任何效果,因为驱动程序将覆盖该值。

    Parameters

    • command: Document

      The command to execute要执行的命令

    • Optional options: RunCommandOptions

      Optional settings for the command命令的可选设置

    Returns Promise<Document>

  • Ping the MongoDB server and retrieve resultsPing MongoDB服务器并检索结果

    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>

  • Retrieve this db's server status.检索此数据库的服务器状态。

    Parameters

    Returns Promise<Document>

  • 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