- Reference >
mongoShell Methods >- Database Methods >
- db.adminCommand()
db.adminCommand()¶
On this page
Definition¶
-
db.adminCommand(command)¶ Provides a helper to run specified database commands against the
admindatabase.Parameter Type Description commanddocument or string A database command, specified either in document form or as a string. If specified as a string, the command cannot include any arguments.
Behavior¶
db.adminCommand runs commands against the admin
database regardless of the database context in which it runs.
The following commands are equivalent:
For a list of available administrative database commands, see Administration Commands.
Note
For a mongod or mongos running with
authorization, the authorized user must have
the appropriate privileges to run the database command. See the
reference documentation for the command for more information on
security requirements.
Examples¶
killOp¶
The following example uses the db.adminCommand()
method to execute a killOp command to terminate an
operation with opid 724. killOp is an administrative
command and must be run against the admin database.
renameCollection¶
The following example uses db.adminCommand() to execute
the renameCollection administrative database command
to rename the orders collection in the test database to
orders-2016.
createUser¶
The following example uses the db.adminCommand() method to
create a user named bruce with the dbOwner role on the
admin database.