@@ -25,18 +25,6 @@ Definition
25
25
collection. The method provides a wrapper around the
26
26
:dbcommand:`drop` command.
27
27
28
- .. note::
29
-
30
- For a sharded cluster, if you use :method:`db.collection.drop()`
31
- and then create a new collection with the same name, you must
32
- either:
33
-
34
- - Flush the cached routing table on every :binary:`~bin.mongos`
35
- using :dbcommand:`flushRouterConfig`.
36
- - Use :method:`db.collection.remove()` to remove the existing
37
- documents and reuse the collection. Use this approach to avoid
38
- flushing the cache.
39
-
40
28
:method:`db.collection.drop()` has the form:
41
29
42
30
.. code-block:: javascript
@@ -92,7 +80,37 @@ Behavior
92
80
encrypted fields. ``mongosh`` *always* drops the specified
93
81
collection and any internal collections related to encrypted
94
82
fields.
95
-
83
+
84
+
85
+ .. _sharding-drop-collections-same-name:
86
+
87
+ Reusing Dropped Collection Names on Sharded Clusters
88
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
+
90
+ On a sharded cluster, if you create a collection that has the same name
91
+ as a previously deleted collection prior to MongoDB 5.0,
92
+ :binary:`~bin.mongos` may forward operations to the wrong shard.
93
+ To avoid this situation use the version-specific instructions below:
94
+
95
+ For a sharded cluster running **MongoDB 5.0 or later**,
96
+ no special action is required. Use the ``drop()`` method
97
+ and then create a new collection with the same name.
98
+
99
+ For a sharded cluster running **MongoDB 4.4 or earlier**,
100
+ if you use the ``drop()`` method and then create a new collection with
101
+ the same name, you must either:
102
+
103
+ - Flush the cached routing table on every :binary:`~bin.mongos`
104
+ using :dbcommand:`flushRouterConfig`.
105
+
106
+ - Use :method:`db.collection.remove()` to remove the existing
107
+ documents and reuse the collection.
108
+
109
+ Flushing the cached routing tables is the preferred procedure because it
110
+ is faster than removing sharded collections with
111
+ :method:`db.collection.remove()`. Only use the ``remove()`` approach if
112
+ you want to avoid flushing the cache.
113
+
96
114
Resource Locking
97
115
~~~~~~~~~~~~~~~~
98
116
0 commit comments