Skip to content

Commit 144c878

Browse files
committed
INTPYTHON-758 - Add append_metadata helper
1 parent ab22353 commit 144c878

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pymongo_vectorsearch_utils/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import logging
22
from typing import Any
33

4+
from pymongo import MongoClient, AsyncMongoClient
5+
from pymongo.driver_info import DriverInfo
6+
47
logger = logging.getLogger(__file__)
58

69

@@ -42,3 +45,9 @@ def oid_to_str(oid: Any) -> str:
4245
24 character hex string.
4346
"""
4447
return str(oid)
48+
49+
50+
def append_client_metadata(client: MongoClient | AsyncMongoClient, driver_info: DriverInfo) -> None:
51+
# append_metadata was added in PyMongo 4.14.0, but is a valid database name on earlier versions
52+
if callable(client.append_metadata):
53+
client.append_metadata(driver_info)

0 commit comments

Comments
 (0)