PYTHON-5166 Allow Database.command to run bulkWrite commands (#2164)

This commit is contained in:
Shane Harvey 2025-02-28 10:48:36 -08:00 committed by GitHub
parent e52965eea4
commit 080c1c6121
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 2 deletions

View File

@ -1,7 +1,26 @@
Changelog
=========
Changes in Version 4.11.0 (YYYY/MM/DD)
Changes in Version 4.11.2 (YYYY/MM/DD)
--------------------------------------
Version 4.11.2 is a bug fix release.
- Fixed a bug where :meth:`~pymongo.database.Database.command` would fail when attempting to run the bulkWrite command.
Issues Resolved
...............
See the `PyMongo 4.11.2 release notes in JIRA`_ for the list of resolved issues in this release.
.. _PyMongo 4.11.2 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=42506
Changes in Version 4.11.1 (2025/02/10)
--------------------------------------
- Fixed support for prebuilt ``ppc64le`` and ``s390x`` wheels.
Changes in Version 4.11.0 (2025/01/28)
--------------------------------------
.. warning:: PyMongo 4.11 drops support for Python 3.8 and PyPy 3.9: Python 3.9+ or PyPy 3.10+ is now required.

View File

@ -105,7 +105,7 @@ _FIELD_MAP = {
"insert": "documents",
"update": "updates",
"delete": "deletes",
"bulkWrite": "bulkWrite",
"bulkWrite": "ops",
}
_UNICODE_REPLACE_CODEC_OPTIONS: CodecOptions[Mapping[str, Any]] = CodecOptions(

View File

@ -430,6 +430,21 @@ class TestDatabase(AsyncIntegrationTest):
for doc in result["cursor"]["firstBatch"]:
self.assertTrue(isinstance(doc["r"], Regex))
async def test_command_bulkWrite(self):
# Ensure bulk write commands can be run directly via db.command().
if async_client_context.version.at_least(8, 0):
await self.client.admin.command(
{
"bulkWrite": 1,
"nsInfo": [{"ns": self.db.test.full_name}],
"ops": [{"insert": 0, "document": {}}],
}
)
await self.db.command({"insert": "test", "documents": [{}]})
await self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]})
await self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]})
await self.db.test.drop()
async def test_cursor_command(self):
db = self.client.pymongo_test
await db.test.drop()

View File

@ -425,6 +425,21 @@ class TestDatabase(IntegrationTest):
for doc in result["cursor"]["firstBatch"]:
self.assertTrue(isinstance(doc["r"], Regex))
def test_command_bulkWrite(self):
# Ensure bulk write commands can be run directly via db.command().
if client_context.version.at_least(8, 0):
self.client.admin.command(
{
"bulkWrite": 1,
"nsInfo": [{"ns": self.db.test.full_name}],
"ops": [{"insert": 0, "document": {}}],
}
)
self.db.command({"insert": "test", "documents": [{}]})
self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]})
self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]})
self.db.test.drop()
def test_cursor_command(self):
db = self.client.pymongo_test
db.test.drop()