diff --git a/pymongo/asynchronous/collection.py b/pymongo/asynchronous/collection.py index ed396fb9c..372cafe5b 100644 --- a/pymongo/asynchronous/collection.py +++ b/pymongo/asynchronous/collection.py @@ -15,6 +15,7 @@ """Collection level utilities for Mongo.""" from __future__ import annotations +import warnings from collections import abc from typing import ( TYPE_CHECKING, @@ -248,6 +249,11 @@ class AsyncCollection(common.BaseObject, Generic[_DocumentType]): if create or kwargs: if _IS_SYNC: + warnings.warn( + "The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0", + DeprecationWarning, + stacklevel=2, + ) self._create(kwargs, session) # type: ignore[unused-coroutine] else: raise ValueError( diff --git a/pymongo/synchronous/collection.py b/pymongo/synchronous/collection.py index 61bd81fd9..c04afbe7c 100644 --- a/pymongo/synchronous/collection.py +++ b/pymongo/synchronous/collection.py @@ -15,6 +15,7 @@ """Collection level utilities for Mongo.""" from __future__ import annotations +import warnings from collections import abc from typing import ( TYPE_CHECKING, @@ -251,6 +252,11 @@ class Collection(common.BaseObject, Generic[_DocumentType]): if create or kwargs: if _IS_SYNC: + warnings.warn( + "The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0", + DeprecationWarning, + stacklevel=2, + ) self._create(kwargs, session) # type: ignore[unused-coroutine] else: raise ValueError("Collection does not support the `create` or `kwargs` arguments.") diff --git a/test/test_collection.py b/test/test_collection.py index 54f76336d..4bbe0fb57 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -198,7 +198,11 @@ class TestCollection(IntegrationTest): "create create_test_no_wc collection", ) db.create_test_no_wc.drop() - Collection(db, name="create_test_no_wc", create=True) + with self.assertWarns( + DeprecationWarning, + msg="The `create` and `kwargs` arguments to Collection are deprecated and will be removed in PyMongo 5.0", + ): + Collection(db, name="create_test_no_wc", create=True) wait_until( lambda: "create_test_no_wc" in db.list_collection_names(), "create create_test_no_wc collection",