-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
db.adminCommand.txt
127 lines (85 loc) · 2.71 KB
/
db.adminCommand.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
=================
db.adminCommand()
=================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: db.adminCommand(command)
Provides a helper to run specified :doc:`database commands
</reference/command>` against the ``admin`` database.
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Parameter
- Type
- Description
* - ``command``
- document or string
- A :term:`database command`, specified either in :term:`document` form
or as a string. If specified as a string, the command cannot include
any arguments.
Behavior
--------
:method:`db.adminCommand` runs commands against the ``admin``
database regardless of the database context in which it runs.
The following commands are equivalent:
.. code-block:: javascript
db.getSiblingDB("admin").runCommand(<command>)
db.adminCommand(<command>)
For a list of available administrative database commands, see
:doc:`/reference/command/nav-administration`.
.. note::
For a :binary:`~bin.mongod` or :binary:`~bin.mongos` running with
:setting:`~security.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.
Response
--------
The method returns a response document that contains the following
fields:
.. include:: /includes/fact-runCommand-results.rst
.. _admincommand-examples:
Examples
--------
killOp
~~~~~~
The following example uses the :method:`db.adminCommand()`
method to execute a :dbcommand:`killOp` command to terminate an
operation with ``opid 724``. :dbcommand:`killOp` is an administrative
command and must be run against the ``admin`` database.
.. code-block:: javascript
db.adminCommand( { "killOp": 1, "op": 724 } )
renameCollection
~~~~~~~~~~~~~~~~
The following example uses :method:`db.adminCommand()` to execute
the :dbcommand:`renameCollection` administrative database command
to rename the ``orders`` collection in the ``test`` database to
``orders-2016``.
.. code-block:: javascript
db.adminCommand(
{
renameCollection: "test.orders",
to: "test.orders-2016"
}
)
createUser
~~~~~~~~~~
The following example uses the :method:`db.adminCommand()` method to
create a user named ``bruce`` with the :authrole:`dbOwner` role on the
``admin`` database.
.. code-block:: javascript
db.adminCommand(
{
createUser: "bruce",
pwd: "bruce123",
roles: [
{ role: "dbOwner", db: "admin" }
]
}
)