Skip to content

Commit 388339e

Browse files
committed
PYTHON-1591 - Deprecate Collection.parallel_scan
1 parent 709b284 commit 388339e

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Deprecations:
6565
:meth:`~pymongo.mongo_client.MongoClient.list_database_names` instead.
6666
- Deprecated :meth:`~pymongo.database.Database.collection_names`. Use
6767
:meth:`~pymongo.database.Database.list_collection_names` instead.
68+
- Deprecated :meth:`~pymongo.collection.Collection.parallel_scan`. MongoDB 4.2
69+
will remove the parallelCollectionScan command.
6870

6971
Unavoidable breaking changes:
7072

pymongo/collection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ def find_raw_batches(self, *args, **kwargs):
14501450
return RawBatchCursor(self, *args, **kwargs)
14511451

14521452
def parallel_scan(self, num_cursors, session=None, **kwargs):
1453-
"""Scan this entire collection in parallel.
1453+
"""**DEPRECATED**: Scan this entire collection in parallel.
14541454
14551455
Returns a list of up to ``num_cursors`` cursors that can be iterated
14561456
concurrently. As long as the collection is not modified during
@@ -1492,6 +1492,9 @@ def parallel_scan(self, num_cursors, session=None, **kwargs):
14921492
14931493
.. note:: Requires server version **>= 2.5.5**.
14941494
1495+
.. versionchanged:: 3.7
1496+
Deprecated.
1497+
14951498
.. versionchanged:: 3.6
14961499
Added ``session`` parameter.
14971500
@@ -1504,6 +1507,9 @@ def parallel_scan(self, num_cursors, session=None, **kwargs):
15041507
Removed support for arbitrary keyword arguments, since
15051508
the parallelCollectionScan command has no optional arguments.
15061509
"""
1510+
warnings.warn("parallel_scan is deprecated. MongoDB 4.2 will remove "
1511+
"the parallelCollectionScan command.",
1512+
DeprecationWarning, stacklevel=2)
15071513
cmd = SON([('parallelCollectionScan', self.__name),
15081514
('numCursors', num_cursors)])
15091515
cmd.update(kwargs)

test/test_collection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,8 @@ def test_aggregation_cursor_alive(self):
16621662
self.assertTrue(cursor.alive)
16631663

16641664
@client_context.require_no_mongos
1665+
@client_context.require_version_max(4, 1, 0)
1666+
@ignore_deprecations
16651667
def test_parallel_scan(self):
16661668
db = self.db
16671669
db.drop_collection("test")
@@ -1688,7 +1690,9 @@ def test_parallel_scan(self):
16881690

16891691
@client_context.require_no_mongos
16901692
@client_context.require_version_min(3, 3, 10)
1693+
@client_context.require_version_max(4, 1, 0)
16911694
@client_context.require_test_commands
1695+
@ignore_deprecations
16921696
def test_parallel_scan_max_time_ms(self):
16931697
self.client.admin.command("configureFailPoint",
16941698
"maxTimeAlwaysTimeOut",

test/test_session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ def test_collection(self):
320320
(coll.aggregate, [[]], {}))
321321

322322
@client_context.require_no_mongos
323+
@client_context.require_version_max(4, 1, 0)
324+
@ignore_deprecations
323325
def test_parallel_collection_scan(self):
324326
listener = self.listener
325327
client = self.client
@@ -771,7 +773,8 @@ def test_reads(self):
771773
self._test_reads(
772774
lambda coll, session: coll.inline_map_reduce(
773775
'function() {}', 'function() {}', session=session))
774-
if not client_context.is_mongos:
776+
if (not client_context.is_mongos and
777+
not client_context.version.at_least(4, 1, 0)):
775778
def scan(coll, session):
776779
cursors = coll.parallel_scan(1, session=session)
777780
for cur in cursors:

0 commit comments

Comments
 (0)