Skip to content

Commit f7da415

Browse files
authored
Merge branch 'master' into PYTHON-4946
2 parents 2103d67 + 4403169 commit f7da415

File tree

16 files changed

+214
-182
lines changed

16 files changed

+214
-182
lines changed

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PyMongo 4.12 brings a number of changes including:
1111
- Support for $lookup in CSFLE and QE supported on MongoDB 8.1+.
1212
- Added :meth:`gridfs.asynchronous.grid_file.AsyncGridFSBucket.rename_by_name` and :meth:`gridfs.grid_file.GridFSBucket.rename_by_name`
1313
for more performant renaming of file revisions.
14+
- Added index hinting support to the
15+
:meth:`~pymongo.asynchronous.collection.AsyncCollection.distinct` and
16+
:meth:`~pymongo.collection.Collection.distinct` commands.
1417

1518
Issues Resolved
1619
...............

pymongo/asynchronous/client_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ def _max_time_expired_error(exc: PyMongoError) -> bool:
458458

459459

460460
# From the transactions spec, all the retryable writes errors plus
461-
# WriteConcernFailed.
461+
# WriteConcernTimeout.
462462
_UNKNOWN_COMMIT_ERROR_CODES: frozenset = _RETRYABLE_ERROR_CODES | frozenset(
463463
[
464-
64, # WriteConcernFailed
464+
64, # WriteConcernTimeout
465465
50, # MaxTimeMSExpired
466466
]
467467
)

pymongo/asynchronous/collection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,7 @@ async def distinct(
31113111
filter: Optional[Mapping[str, Any]] = None,
31123112
session: Optional[AsyncClientSession] = None,
31133113
comment: Optional[Any] = None,
3114+
hint: Optional[_IndexKeyHint] = None,
31143115
**kwargs: Any,
31153116
) -> list:
31163117
"""Get a list of distinct values for `key` among all documents
@@ -3138,8 +3139,15 @@ async def distinct(
31383139
:class:`~pymongo.asynchronous.client_session.AsyncClientSession`.
31393140
:param comment: A user-provided comment to attach to this
31403141
command.
3142+
:param hint: An index to use to support the query
3143+
predicate specified either by its string name, or in the same
3144+
format as passed to :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index`
3145+
(e.g. ``[('field', ASCENDING)]``).
31413146
:param kwargs: See list of options above.
31423147
3148+
.. versionchanged:: 4.12
3149+
Added ``hint`` parameter.
3150+
31433151
.. versionchanged:: 3.6
31443152
Added ``session`` parameter.
31453153
@@ -3158,6 +3166,10 @@ async def distinct(
31583166
cmd.update(kwargs)
31593167
if comment is not None:
31603168
cmd["comment"] = comment
3169+
if hint is not None:
3170+
if not isinstance(hint, str):
3171+
hint = helpers_shared._index_document(hint)
3172+
cmd["hint"] = hint # type: ignore[assignment]
31613173

31623174
async def _cmd(
31633175
session: Optional[AsyncClientSession],

pymongo/synchronous/client_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ def _max_time_expired_error(exc: PyMongoError) -> bool:
457457

458458

459459
# From the transactions spec, all the retryable writes errors plus
460-
# WriteConcernFailed.
460+
# WriteConcernTimeout.
461461
_UNKNOWN_COMMIT_ERROR_CODES: frozenset = _RETRYABLE_ERROR_CODES | frozenset(
462462
[
463-
64, # WriteConcernFailed
463+
64, # WriteConcernTimeout
464464
50, # MaxTimeMSExpired
465465
]
466466
)

pymongo/synchronous/collection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,6 +3104,7 @@ def distinct(
31043104
filter: Optional[Mapping[str, Any]] = None,
31053105
session: Optional[ClientSession] = None,
31063106
comment: Optional[Any] = None,
3107+
hint: Optional[_IndexKeyHint] = None,
31073108
**kwargs: Any,
31083109
) -> list:
31093110
"""Get a list of distinct values for `key` among all documents
@@ -3131,8 +3132,15 @@ def distinct(
31313132
:class:`~pymongo.client_session.ClientSession`.
31323133
:param comment: A user-provided comment to attach to this
31333134
command.
3135+
:param hint: An index to use to support the query
3136+
predicate specified either by its string name, or in the same
3137+
format as passed to :meth:`~pymongo.collection.Collection.create_index`
3138+
(e.g. ``[('field', ASCENDING)]``).
31343139
:param kwargs: See list of options above.
31353140
3141+
.. versionchanged:: 4.12
3142+
Added ``hint`` parameter.
3143+
31363144
.. versionchanged:: 3.6
31373145
Added ``session`` parameter.
31383146
@@ -3151,6 +3159,10 @@ def distinct(
31513159
cmd.update(kwargs)
31523160
if comment is not None:
31533161
cmd["comment"] = comment
3162+
if hint is not None:
3163+
if not isinstance(hint, str):
3164+
hint = helpers_shared._index_document(hint)
3165+
cmd["hint"] = hint # type: ignore[assignment]
31543166

31553167
def _cmd(
31563168
session: Optional[ClientSession],

test/bson_binary_vector/float32.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
"description": "Infinity Vector FLOAT32",
3434
"valid": true,
35-
"vector": ["-inf", 0.0, "inf"],
35+
"vector": [{"$numberDouble": "-Infinity"}, 0.0, {"$numberDouble": "Infinity"} ],
3636
"dtype_hex": "0x27",
3737
"dtype_alias": "FLOAT32",
3838
"padding": 0,

test/gridfs/delete.json

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@
4949
"uploadDate": {
5050
"$date": "1970-01-01T00:00:00.000Z"
5151
},
52-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
5352
"filename": "length-0",
54-
"contentType": "application/octet-stream",
55-
"aliases": [],
5653
"metadata": {}
5754
},
5855
{
@@ -64,10 +61,7 @@
6461
"uploadDate": {
6562
"$date": "1970-01-01T00:00:00.000Z"
6663
},
67-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
6864
"filename": "length-0-with-empty-chunk",
69-
"contentType": "application/octet-stream",
70-
"aliases": [],
7165
"metadata": {}
7266
},
7367
{
@@ -79,10 +73,7 @@
7973
"uploadDate": {
8074
"$date": "1970-01-01T00:00:00.000Z"
8175
},
82-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
8376
"filename": "length-2",
84-
"contentType": "application/octet-stream",
85-
"aliases": [],
8677
"metadata": {}
8778
},
8879
{
@@ -94,10 +85,7 @@
9485
"uploadDate": {
9586
"$date": "1970-01-01T00:00:00.000Z"
9687
},
97-
"md5": "dd254cdc958e53abaa67da9f797125f5",
9888
"filename": "length-8",
99-
"contentType": "application/octet-stream",
100-
"aliases": [],
10189
"metadata": {}
10290
}
10391
]
@@ -197,10 +185,7 @@
197185
"uploadDate": {
198186
"$date": "1970-01-01T00:00:00.000Z"
199187
},
200-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
201188
"filename": "length-0-with-empty-chunk",
202-
"contentType": "application/octet-stream",
203-
"aliases": [],
204189
"metadata": {}
205190
},
206191
{
@@ -212,10 +197,7 @@
212197
"uploadDate": {
213198
"$date": "1970-01-01T00:00:00.000Z"
214199
},
215-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
216200
"filename": "length-2",
217-
"contentType": "application/octet-stream",
218-
"aliases": [],
219201
"metadata": {}
220202
},
221203
{
@@ -227,10 +209,7 @@
227209
"uploadDate": {
228210
"$date": "1970-01-01T00:00:00.000Z"
229211
},
230-
"md5": "dd254cdc958e53abaa67da9f797125f5",
231212
"filename": "length-8",
232-
"contentType": "application/octet-stream",
233-
"aliases": [],
234213
"metadata": {}
235214
}
236215
]
@@ -330,10 +309,7 @@
330309
"uploadDate": {
331310
"$date": "1970-01-01T00:00:00.000Z"
332311
},
333-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
334312
"filename": "length-0",
335-
"contentType": "application/octet-stream",
336-
"aliases": [],
337313
"metadata": {}
338314
},
339315
{
@@ -345,10 +321,7 @@
345321
"uploadDate": {
346322
"$date": "1970-01-01T00:00:00.000Z"
347323
},
348-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
349324
"filename": "length-2",
350-
"contentType": "application/octet-stream",
351-
"aliases": [],
352325
"metadata": {}
353326
},
354327
{
@@ -360,10 +333,7 @@
360333
"uploadDate": {
361334
"$date": "1970-01-01T00:00:00.000Z"
362335
},
363-
"md5": "dd254cdc958e53abaa67da9f797125f5",
364336
"filename": "length-8",
365-
"contentType": "application/octet-stream",
366-
"aliases": [],
367337
"metadata": {}
368338
}
369339
]
@@ -448,10 +418,7 @@
448418
"uploadDate": {
449419
"$date": "1970-01-01T00:00:00.000Z"
450420
},
451-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
452421
"filename": "length-0",
453-
"contentType": "application/octet-stream",
454-
"aliases": [],
455422
"metadata": {}
456423
},
457424
{
@@ -463,10 +430,7 @@
463430
"uploadDate": {
464431
"$date": "1970-01-01T00:00:00.000Z"
465432
},
466-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
467433
"filename": "length-0-with-empty-chunk",
468-
"contentType": "application/octet-stream",
469-
"aliases": [],
470434
"metadata": {}
471435
},
472436
{
@@ -478,10 +442,7 @@
478442
"uploadDate": {
479443
"$date": "1970-01-01T00:00:00.000Z"
480444
},
481-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
482445
"filename": "length-2",
483-
"contentType": "application/octet-stream",
484-
"aliases": [],
485446
"metadata": {}
486447
}
487448
]
@@ -554,10 +515,7 @@
554515
"uploadDate": {
555516
"$date": "1970-01-01T00:00:00.000Z"
556517
},
557-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
558518
"filename": "length-0",
559-
"contentType": "application/octet-stream",
560-
"aliases": [],
561519
"metadata": {}
562520
},
563521
{
@@ -569,10 +527,7 @@
569527
"uploadDate": {
570528
"$date": "1970-01-01T00:00:00.000Z"
571529
},
572-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
573530
"filename": "length-0-with-empty-chunk",
574-
"contentType": "application/octet-stream",
575-
"aliases": [],
576531
"metadata": {}
577532
},
578533
{
@@ -584,10 +539,7 @@
584539
"uploadDate": {
585540
"$date": "1970-01-01T00:00:00.000Z"
586541
},
587-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
588542
"filename": "length-2",
589-
"contentType": "application/octet-stream",
590-
"aliases": [],
591543
"metadata": {}
592544
},
593545
{
@@ -599,10 +551,7 @@
599551
"uploadDate": {
600552
"$date": "1970-01-01T00:00:00.000Z"
601553
},
602-
"md5": "dd254cdc958e53abaa67da9f797125f5",
603554
"filename": "length-8",
604-
"contentType": "application/octet-stream",
605-
"aliases": [],
606555
"metadata": {}
607556
}
608557
]
@@ -719,10 +668,7 @@
719668
"uploadDate": {
720669
"$date": "1970-01-01T00:00:00.000Z"
721670
},
722-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
723671
"filename": "length-0",
724-
"contentType": "application/octet-stream",
725-
"aliases": [],
726672
"metadata": {}
727673
},
728674
{
@@ -734,10 +680,7 @@
734680
"uploadDate": {
735681
"$date": "1970-01-01T00:00:00.000Z"
736682
},
737-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
738683
"filename": "length-0-with-empty-chunk",
739-
"contentType": "application/octet-stream",
740-
"aliases": [],
741684
"metadata": {}
742685
},
743686
{
@@ -749,10 +692,7 @@
749692
"uploadDate": {
750693
"$date": "1970-01-01T00:00:00.000Z"
751694
},
752-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
753695
"filename": "length-2",
754-
"contentType": "application/octet-stream",
755-
"aliases": [],
756696
"metadata": {}
757697
}
758698
]

test/gridfs/download.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@
4949
"uploadDate": {
5050
"$date": "1970-01-01T00:00:00.000Z"
5151
},
52-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
5352
"filename": "length-0",
54-
"contentType": "application/octet-stream",
55-
"aliases": [],
5653
"metadata": {}
5754
},
5855
{
@@ -64,10 +61,7 @@
6461
"uploadDate": {
6562
"$date": "1970-01-01T00:00:00.000Z"
6663
},
67-
"md5": "d41d8cd98f00b204e9800998ecf8427e",
6864
"filename": "length-0-with-empty-chunk",
69-
"contentType": "application/octet-stream",
70-
"aliases": [],
7165
"metadata": {}
7266
},
7367
{
@@ -79,10 +73,7 @@
7973
"uploadDate": {
8074
"$date": "1970-01-01T00:00:00.000Z"
8175
},
82-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
8376
"filename": "length-2",
84-
"contentType": "application/octet-stream",
85-
"aliases": [],
8677
"metadata": {}
8778
},
8879
{
@@ -94,10 +85,7 @@
9485
"uploadDate": {
9586
"$date": "1970-01-01T00:00:00.000Z"
9687
},
97-
"md5": "dd254cdc958e53abaa67da9f797125f5",
9888
"filename": "length-8",
99-
"contentType": "application/octet-stream",
100-
"aliases": [],
10189
"metadata": {}
10290
},
10391
{
@@ -109,10 +97,7 @@
10997
"uploadDate": {
11098
"$date": "1970-01-01T00:00:00.000Z"
11199
},
112-
"md5": "57d83cd477bfb1ccd975ab33d827a92b",
113100
"filename": "length-10",
114-
"contentType": "application/octet-stream",
115-
"aliases": [],
116101
"metadata": {}
117102
},
118103
{
@@ -124,9 +109,6 @@
124109
"uploadDate": {
125110
"$date": "1970-01-01T00:00:00.000Z"
126111
},
127-
"md5": "c700ed4fdb1d27055aa3faa2c2432283",
128-
"contentType": "application/octet-stream",
129-
"aliases": [],
130112
"metadata": {}
131113
}
132114
]

0 commit comments

Comments
 (0)