Skip to content

Commit 1145c9d

Browse files
authored
PYTHON-5046 Support $lookup in CSFLE and QE (#2210)
1 parent 737a1b7 commit 1145c9d

File tree

11 files changed

+730
-15
lines changed

11 files changed

+730
-15
lines changed

doc/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PyMongo 4.12 brings a number of changes including:
88

99
- Support for configuring DEK cache lifetime via the ``key_expiration_ms`` argument to
1010
:class:`~pymongo.encryption_options.AutoEncryptionOpts`.
11+
- Support for $lookup in CSFLE and QE supported on MongoDB 8.1+.
1112

1213
Issues Resolved
1314
...............

pymongo/asynchronous/encryption.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ async def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
242242
)
243243
raise exc from final_err
244244

245-
async def collection_info(self, database: str, filter: bytes) -> Optional[bytes]:
245+
async def collection_info(self, database: str, filter: bytes) -> Optional[list[bytes]]:
246246
"""Get the collection info for a namespace.
247247
248248
The returned collection info is passed to libmongocrypt which reads
@@ -251,14 +251,12 @@ async def collection_info(self, database: str, filter: bytes) -> Optional[bytes]
251251
:param database: The database on which to run listCollections.
252252
:param filter: The filter to pass to listCollections.
253253
254-
:return: The first document from the listCollections command response as BSON.
254+
:return: All documents from the listCollections command response as BSON.
255255
"""
256256
async with await self.client_ref()[database].list_collections(
257257
filter=RawBSONDocument(filter)
258258
) as cursor:
259-
async for doc in cursor:
260-
return _dict_to_bson(doc, False, _DATA_KEY_OPTS)
261-
return None
259+
return [_dict_to_bson(doc, False, _DATA_KEY_OPTS) async for doc in cursor]
262260

263261
def spawn(self) -> None:
264262
"""Spawn mongocryptd.
@@ -551,7 +549,7 @@ def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions:
551549
# For compat with pymongocrypt <1.13, avoid setting the default key_expiration_ms.
552550
if kwargs.get("key_expiration_ms") is None:
553551
kwargs.pop("key_expiration_ms", None)
554-
return MongoCryptOptions(**kwargs)
552+
return MongoCryptOptions(**kwargs, enable_multiple_collinfo=True)
555553

556554

557555
class AsyncClientEncryption(Generic[_DocumentType]):

pymongo/synchronous/encryption.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
241241
)
242242
raise exc from final_err
243243

244-
def collection_info(self, database: str, filter: bytes) -> Optional[bytes]:
244+
def collection_info(self, database: str, filter: bytes) -> Optional[list[bytes]]:
245245
"""Get the collection info for a namespace.
246246
247247
The returned collection info is passed to libmongocrypt which reads
@@ -250,12 +250,10 @@ def collection_info(self, database: str, filter: bytes) -> Optional[bytes]:
250250
:param database: The database on which to run listCollections.
251251
:param filter: The filter to pass to listCollections.
252252
253-
:return: The first document from the listCollections command response as BSON.
253+
:return: All documents from the listCollections command response as BSON.
254254
"""
255255
with self.client_ref()[database].list_collections(filter=RawBSONDocument(filter)) as cursor:
256-
for doc in cursor:
257-
return _dict_to_bson(doc, False, _DATA_KEY_OPTS)
258-
return None
256+
return [_dict_to_bson(doc, False, _DATA_KEY_OPTS) for doc in cursor]
259257

260258
def spawn(self) -> None:
261259
"""Spawn mongocryptd.
@@ -548,7 +546,7 @@ def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions:
548546
# For compat with pymongocrypt <1.13, avoid setting the default key_expiration_ms.
549547
if kwargs.get("key_expiration_ms") is None:
550548
kwargs.pop("key_expiration_ms", None)
551-
return MongoCryptOptions(**kwargs)
549+
return MongoCryptOptions(**kwargs, enable_multiple_collinfo=True)
552550

553551

554552
class ClientEncryption(Generic[_DocumentType]):

0 commit comments

Comments
 (0)