@@ -25,18 +25,6 @@ Definition
2525 collection. The method provides a wrapper around the
2626 :dbcommand:`drop` command.
2727
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-
4028 :method:`db.collection.drop()` has the form:
4129
4230 .. code-block:: javascript
@@ -92,7 +80,37 @@ Behavior
9280 encrypted fields. ``mongosh`` *always* drops the specified
9381 collection and any internal collections related to encrypted
9482 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+
96114Resource Locking
97115~~~~~~~~~~~~~~~~
98116
0 commit comments