From 7564e9ef37b1613aa76915ced6c0af1fe0a210df Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 2 Dec 2025 13:10:16 -0500 Subject: [PATCH 1/2] Revert #36949 --- sdks/python/apache_beam/io/mongodbio.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sdks/python/apache_beam/io/mongodbio.py b/sdks/python/apache_beam/io/mongodbio.py index e8602edd40cd..8ae8876bb48a 100644 --- a/sdks/python/apache_beam/io/mongodbio.py +++ b/sdks/python/apache_beam/io/mongodbio.py @@ -97,6 +97,7 @@ from pymongo import DESCENDING from pymongo import MongoClient from pymongo import ReplaceOne + from pymongo.driver_info import DriverInfo except ImportError: objectid = None json_util = None @@ -105,6 +106,7 @@ DESCENDING = -1 MongoClient = None ReplaceOne = None + DriverInfo = None _LOGGER.warning("Could not find a compatible bson package.") __all__ = ["ReadFromMongoDB", "WriteToMongoDB"] @@ -263,6 +265,12 @@ def __init__( self.spec = extra_client_params self.bucket_auto = bucket_auto + if "driver" not in self.spec: + self.spec["driver"] = DriverInfo( + name="Apache Beam", + version=beam.__version__, + ) + def estimate_size(self): with MongoClient(self.uri, **self.spec) as client: return client[self.db].command("collstats", self.coll).get("size") From 19bdb011b23fc620c0775e7604e4d8f323a5a6e9 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 2 Dec 2025 14:47:26 -0500 Subject: [PATCH 2/2] Update _MongoSink --- sdks/python/apache_beam/io/mongodbio.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdks/python/apache_beam/io/mongodbio.py b/sdks/python/apache_beam/io/mongodbio.py index 8ae8876bb48a..aede27674f8f 100644 --- a/sdks/python/apache_beam/io/mongodbio.py +++ b/sdks/python/apache_beam/io/mongodbio.py @@ -785,6 +785,12 @@ def __init__(self, uri=None, db=None, coll=None, extra_params=None): self.spec = extra_params self.client = None + if "driver" not in self.spec: + self.spec["driver"] = DriverInfo( + name="Apache Beam", + version=beam.__version__, + ) + def write(self, documents): if self.client is None: self.client = MongoClient(host=self.uri, **self.spec)