@@ -2,7 +2,12 @@ If you intend to create a new database with the same name as the dropped
2
2
database, you must follow these additional steps for using the
3
3
:dbcommand: `dropDatabase ` command, specific to your version of MongoDB:
4
4
5
- - For **MongoDB 4.4 and later **, you must:
5
+ - For **MongoDB 5.0 and later **, you must:
6
+
7
+ #. Run the :dbcommand: `dropDatabase ` command on a
8
+ :binary: `~bin.mongos `, no additional steps required.
9
+
10
+ - For **MongoDB 4.4 **, you must:
6
11
7
12
#. Run the :dbcommand: `dropDatabase ` command on a
8
13
:binary: `~bin.mongos `.
@@ -24,54 +29,6 @@ database, you must follow these additional steps for using the
24
29
:binary: `~bin.mongos ` instances before reading or writing to that
25
30
database.
26
31
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.
74
-
75
32
These steps ensure that all cluster nodes refresh their metadata cache,
76
33
which includes the location of the :ref: `primary shard<primary-shard> `
77
34
for the new database. Otherwise, you may miss data on reads, and may not
0 commit comments