Class: Admin

Admin

new Admin(){Admin}

Create a new Admin instance (INTERNAL TYPE, do not instantiate directly)

Returns:
collection instance.

Methods

addUser(username, password, options, callback){Promise}

Add a user to the database.

Name Type Description
username string

The username.

password string

The password.

options object optional

Optional settings.

Name Type Default Description
w number | string optional

The write concern.

wtimeout number optional

The write concern timeout.

j boolean false optional

Specify a journal write concern.

fsync boolean false optional

Specify a file sync write concern.

customData object optional

Custom data associated with the user (only Mongodb 2.6 or higher)

roles Array.<object> optional

Roles associated with the created user (only Mongodb 2.6 or higher)

session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback

Returns:
Promise if no callback passed

buildInfo(options, callback){Promise}

Retrieve the server information for the current
instance of the db client

Name Type Description
options Object optional

optional parameters for this operation

Name Type Description
session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback

Returns:
Promise if no callback passed

command(command, options, callback){Promise}

Execute a command

Name Type Description
command object

The command hash

options object optional

Optional settings.

Name Type Description
readPreference ReadPreference | string optional

The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).

maxTimeMS number optional

Number of milliseconds to wait before aborting the query.

callback Admin~resultCallback optional

The command result callback

Returns:
Promise if no callback passed

listDatabases(options, callback){Promise}

List the available databases

Name Type Description
options object optional

Optional settings.

Name Type Default Description
nameOnly boolean false optional

Whether the command should return only db names, or names and size info.

session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback.

Returns:
Promise if no callback passed

ping(options, callback){Promise}

Ping the MongoDB server and retrieve results

Name Type Description
options Object optional

optional parameters for this operation

Name Type Description
session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback

Returns:
Promise if no callback passed

removeUser(username, options, callback){Promise}

Remove a user from a database

Name Type Description
username string

The username.

options object optional

Optional settings.

Name Type Default Description
w number | string optional

The write concern.

wtimeout number optional

The write concern timeout.

j boolean false optional

Specify a journal write concern.

fsync boolean false optional

Specify a file sync write concern.

session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback

Returns:
Promise if no callback passed

replSetGetStatus(options, callback){Promise}

Get ReplicaSet status

Name Type Description
options Object optional

optional parameters for this operation

Name Type Description
session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback.

Returns:
Promise if no callback passed

serverInfo(options, callback){Promise}

Retrieve the server information for the current
instance of the db client

Name Type Description
options Object optional

optional parameters for this operation

Name Type Description
session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback

Returns:
Promise if no callback passed

serverStatus(options, callback){Promise}

Retrieve this db's server status.

Name Type Description
options Object optional

optional parameters for this operation

Name Type Description
session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback

Returns:
Promise if no callback passed

validateCollection(collectionName, options, callback){Promise}

Validate an existing collection

Name Type Description
collectionName string

The name of the collection to validate.

options object optional

Optional settings.

Name Type Description
background boolean optional

Validates a collection in the background, without interrupting read or write traffic (only in MongoDB 4.4+)

session ClientSession optional

optional session to use for this operation

callback Admin~resultCallback optional

The command result callback.

Returns:
Promise if no callback passed

Type Definitions

resultCallback(error, result)

The callback format for results

Name Type Description
error MongoError

An error instance representing the error during the execution.

result object

The result object if the command was executed successfully.