Skip to content

Commit b4e3a00

Browse files
Bob GrabarSam Kleinman
authored andcommitted
DOCS-2489 clarify that removeShard is run on admin db
Signed-off-by: Sam Kleinman <[email protected]>
1 parent 230eaff commit b4e3a00

File tree

2 files changed

+85
-33
lines changed

2 files changed

+85
-33
lines changed

source/reference/command/removeShard.txt

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,71 @@ removeShard
66

77
.. dbcommand:: removeShard
88

9-
Starts the process of removing a shard from a :term:`cluster
10-
<sharded cluster>`. This
11-
is a multi-stage process. Begin by issuing the following command:
9+
Removes a shard from a :term:`sharded cluster`. When you run
10+
:dbcommand:`removeShard`, MongoDB first moves the shard's chunks to
11+
other shards in the cluster. Then MongoDB removes the shard.
12+
13+
To run the command you must have administrative access. Either run
14+
:dbcommand:`removeShard` from the admin database or run it with the
15+
:method:`sh._adminCommand` command.
16+
17+
The command takes the following form:
1218

1319
.. code-block:: javascript
1420

15-
{ removeShard : "[shardName]" }
21+
use admin
22+
db.runCommand( { removeShard : "<shardName>" } )
1623

17-
The balancer will then migrate chunks from the shard specified by
18-
``[shardName]``. This process happens slowly to avoid placing
19-
undue load on the overall cluster.
24+
Behavior
25+
--------
2026

21-
The command returns immediately, with the following message:
27+
When you run :dbcommand:`removeShard`, the command returns immediately,
28+
with the following message:
2229

23-
.. code-block:: javascript
30+
.. code-block:: javascript
2431

25-
{ msg : "draining started successfully" , state: "started" , shard: "shardName" , ok : 1 }
32+
{
33+
"msg" : "draining started successfully",
34+
"state" : "started",
35+
"shard" : "bristol01",
36+
"ok" : 1
37+
}
2638

27-
If you run the command again, you'll see the following progress
28-
output:
39+
The balancer migrates chunks from shard ``bristol01``.
40+
This process happens slowly to avoid placing undue load on the overall
41+
cluster.
2942

30-
.. code-block:: javascript
43+
If you run the command again, you'll see the following progress output:
3144

32-
{ msg: "draining ongoing" , state: "ongoing" , remaining: { chunks: 23 , dbs: 1 }, ok: 1 }
45+
.. code-block:: javascript
3346

34-
The ``remaining`` :term:`document` specifies how many chunks and
35-
databases remain on the shard. Use :method:`db.printShardingStatus()`
36-
to list the databases that you must move from the shard.
47+
{
48+
"msg" : "draining ongoing",
49+
"state" : "ongoing",
50+
"remaining" : {
51+
"chunks" : 23,
52+
"dbs" : 1
53+
},
54+
"ok" : 1
55+
}
3756

38-
Each database in a sharded cluster has a primary shard. If the
39-
shard you want to remove is also the primary of one of the cluster's
40-
databases, then you must manually move the database to a new
41-
shard. This can be only after the shard is empty. See the
42-
:dbcommand:`movePrimary` command for details.
57+
The ``remaining`` :term:`document` specifies how many chunks and databases
58+
remain on the shard. Use :method:`db.printShardingStatus()` to list the
59+
databases that you must move from the shard.
4360

44-
After removing all chunks and databases from the shard, you
45-
may issue the command again, to return:
61+
Each database in a sharded cluster has a primary shard. If the shard you
62+
want to remove is also the primary of one of the cluster's databases, then
63+
you must manually move the database to a new shard. This can be done only
64+
after the shard is empty. See the :dbcommand:`movePrimary` command for details.
4665

47-
.. code-block:: javascript
66+
After removing all chunks and databases from the shard, if you issue the
67+
command again it returns:
68+
69+
.. code-block:: javascript
4870

49-
{ msg: "remove shard completed successfully", state: "completed", host: "shardName", ok : 1 }
71+
{
72+
"msg" : "removeshard completed successfully",
73+
"state" : "completed",
74+
"shard" : "bristol01",
75+
"ok" : 1
76+
}

source/tutorial/remove-shards-from-cluster.txt

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,26 @@ The ``shards._id`` field lists the name of each shard.
6060
Remove Chunks from the Shard
6161
----------------------------
6262

63-
Run the :dbcommand:`removeShard` command. This begins "draining" chunks
63+
From the ``admin`` database, run the :dbcommand:`removeShard` command.
64+
This begins "draining" chunks
6465
from the shard you are removing to other shards in the cluster. For
6566
example, for a shard named ``mongodb0``, run:
6667

6768
.. code-block:: javascript
6869

70+
use admin
6971
db.runCommand( { removeShard: "mongodb0" } )
7072

7173
This operation returns immediately, with the following response:
7274

7375
.. code-block:: javascript
7476

75-
{ msg : "draining started successfully" , state: "started" , shard :"mongodb0" , ok : 1 }
77+
{
78+
"msg" : "draining started successfully",
79+
"state" : "started",
80+
"shard" : "mongodb0",
81+
"ok" : 1
82+
}
7683

7784
Depending on your network capacity and the amount of data, this
7885
operation can take from a few minutes to several days to complete.
@@ -83,24 +90,36 @@ Check the Status of the Migration
8390
---------------------------------
8491

8592
To check the progress of the migration at any stage in the process, run
86-
:dbcommand:`removeShard`. For example, for a shard named ``mongodb0``, run:
93+
:dbcommand:`removeShard` from the ``admin`` database again. For example,
94+
for a shard named ``mongodb0``, run:
8795

8896
.. code-block:: javascript
8997

98+
use admin
9099
db.runCommand( { removeShard: "mongodb0" } )
91100

92101
The command returns output similar to the following:
93102

94103
.. code-block:: javascript
95104

96-
{ msg: "draining ongoing" , state: "ongoing" , remaining: { chunks: NumberLong(42), dbs : NumberLong(1) }, ok: 1 }
105+
{
106+
"msg" : "draining ongoing",
107+
"state" : "ongoing",
108+
"remaining" : {
109+
"chunks" : 42,
110+
"dbs" : 1
111+
},
112+
"ok" : 1
113+
}
97114

98115
In the output, the ``remaining`` document displays the remaining number
99116
of chunks that MongoDB must migrate to other shards and the number of
100117
MongoDB databases that have "primary" status on this shard.
101118

102119
Continue checking the status of the `removeShard` command until the
103-
number of chunks remaining is ``0``. Then proceed to the next step.
120+
number of chunks remaining is ``0``. Always run the command on the
121+
``admin`` database. If you are on a database other than ``admin``, you can
122+
use :method:`sh._adminCommand` to run the command on ``admin``.
104123

105124
.. _remove-shard-move-unsharded-databases:
106125

@@ -165,13 +184,19 @@ To clean up all metadata information and finalize the removal, run
165184

166185
.. code-block:: javascript
167186

187+
use admin
168188
db.runCommand( { removeShard: "mongodb0" } )
169189

170190
A success message appears at completion:
171191

172192
.. code-block:: javascript
173193

174-
{ msg: "remove shard completed successfully" , state: "completed", host: "mongodb0", ok : 1 }
194+
{
195+
"msg" : "removeshard completed successfully",
196+
"state" : "completed",
197+
"shard" : "mongodb0",
198+
"ok" : 1
199+
}
175200

176-
Once the value of the ``stage`` field is "completed", you may safely
201+
Once the value of the ``state`` field is "completed", you may safely
177202
stop the processes comprising the ``mongodb0`` shard.

0 commit comments

Comments
 (0)