Skip to content

Commit 9d960c8

Browse files
committed
DOCS-14619 clarify dropDatabases sharded cluster procedure
1 parent b8bd801 commit 9d960c8

File tree

2 files changed

+66
-21
lines changed

2 files changed

+66
-21
lines changed

source/includes/warning-dropDatabase-shardedCluster.rst

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,76 @@
1-
For MongoDB 4.2 and previous, when executing the
2-
:dbcommand:`dropDatabase` command, you must perform the following
3-
additional steps if you intend to create a new database with the same
4-
name as the dropped database.
1+
If you intend to create a new database with the same name as the dropped
2+
database, you must follow these additional steps for using the
3+
:dbcommand:`dropDatabase` command, specific to your version of MongoDB:
54

6-
.. note::
5+
- For **MongoDB 4.4 and later**, you must:
76

8-
MongoDB 4.4 does not require these additional steps when dropping and
9-
recreating a database with the same name.
7+
#. Run the :dbcommand:`dropDatabase` command on a
8+
:binary:`~bin.mongos`.
109

11-
- For **MongoDB 4.2**, you must either:
10+
#. Once the command successfully completes, run the
11+
:dbcommand:`dropDatabase` command once more on a
12+
:binary:`~bin.mongos`.
1213

13-
- Restart all :binary:`~bin.mongos` instances and all
14-
:binary:`~bin.mongod` shard members (including the secondary
15-
members);
14+
- For **MongoDB 4.2**, you must:
1615

17-
- Use the :dbcommand:`flushRouterConfig` command on all
18-
:binary:`~bin.mongos` instances and all :binary:`~bin.mongod`
19-
shard members (including the secondary members) before reading
20-
or writing to that database.
16+
#. Run the :dbcommand:`dropDatabase` command on a
17+
:binary:`~bin.mongos`.
2118

22-
- For **MongoDB 4.0 and earlier**, you must either:
19+
#. Once the command successfully completes, run the
20+
:dbcommand:`dropDatabase` command once more on a
21+
:binary:`~bin.mongos`.
2322

24-
- Restart all :binary:`~bin.mongos` instances;
23+
#. Use the :dbcommand:`flushRouterConfig` command on **all**
24+
:binary:`~bin.mongos` instances before reading or writing to that
25+
database.
2526

26-
- Use the :dbcommand:`flushRouterConfig` command on all
27-
:binary:`~bin.mongos` instances before reading or writing to that
28-
database.
27+
- For **MongoDB 4.0 and earlier**, you must:
28+
29+
#. Run the :dbcommand:`dropDatabase` command on a
30+
:binary:`~bin.mongos`.
31+
32+
#. Connect to each shard's :term:`primary` and verify that the
33+
namespace has been dropped. If it has not, rerun the
34+
:dbcommand:`dropDatabase` command again directly from the
35+
:term:`primary`.
36+
37+
#. Connect to a :binary:`~bin.mongos`, switch to the
38+
:term:`config database`, and remove any reference to the removed
39+
namespace from the ``databases``, ``collections``, ``chunks``,
40+
``tags``, and ``locks`` collections:
41+
42+
.. code-block:: javascript
43+
44+
use config
45+
db.collections.remove( { _id: /^DATABASE\./ }, {writeConcern: {w: 'majority' }} )
46+
db.databases.remove( { _id: "DATABASE" }, {writeConcern: {w: 'majority' }} )
47+
db.chunks.remove( { ns: /^DATABASE\./ }, {writeConcern: {w: 'majority' }} )
48+
db.tags.remove( { ns: /^DATABASE\./ }, {writeConcern: {w: 'majority' }} )
49+
db.locks.remove( { _id: /^DATABASE\./ }, {writeConcern: {w: 'majority' }} )
50+
51+
Where ``DATABASE`` represents the namespace of the database you
52+
just dropped.
53+
54+
#. Connect to the :term:`primary` of each shard, and remove any
55+
reference to the removed namespace from the ``cache.databases``,
56+
``cache.collections``, and ``cache.chunks.DATABASE.COLLECTION``
57+
collections:
58+
59+
.. code-block:: javascript
60+
61+
db.getSiblingDB("config").cache.databases.remove({_id:"DATABASE"}, {writeConcern: {w: 'majority' }});
62+
db.getSiblingDB("config").cache.collections.remove({_id:/^DATABASE.*/}, {writeConcern: {w: 'majority' }});
63+
db.getSiblingDB("config").getCollectionNames().forEach(function(y) {
64+
if(y.indexOf("cache.chunks.DATABASE.") == 0)
65+
db.getSiblingDB("config").getCollection(y).drop()
66+
})
67+
68+
Where ``DATABASE`` represents the namespace of the database you
69+
just dropped.
70+
71+
#. Use the :dbcommand:`flushRouterConfig` command on **all**
72+
:binary:`~bin.mongos` instances before reading or writing to that
73+
database.
2974

3075
These steps ensure that all cluster nodes refresh their metadata cache,
3176
which includes the location of the :ref:`primary shard<primary-shard>`

source/reference/command/dropDatabase.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Indexes
9595
Replica Set and Sharded Clusters
9696
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9797

98-
.. versionchanged:: 3.6
98+
.. versionchanged:: 4.4
9999

100100
Replica Sets
101101
At minimum, :dbcommand:`dropDatabase` waits until all collections

0 commit comments

Comments
 (0)