Skip to content

Commit 3feb663

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents 63c3739 + 4403169 commit 3feb663

23 files changed

+968
-699
lines changed

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PyMongo 4.12 brings a number of changes including:
99
- Support for configuring DEK cache lifetime via the ``key_expiration_ms`` argument to
1010
:class:`~pymongo.encryption_options.AutoEncryptionOpts`.
1111
- Support for $lookup in CSFLE and QE supported on MongoDB 8.1+.
12+
- Added index hinting support to the
13+
:meth:`~pymongo.asynchronous.collection.AsyncCollection.distinct` and
14+
:meth:`~pymongo.collection.Collection.distinct` commands.
1215

1316
Issues Resolved
1417
...............

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/command_monitoring/unacknowledged-client-bulkWrite.json

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,34 @@
9595
"ordered": false
9696
},
9797
"expectResult": {
98-
"insertedCount": {
99-
"$$unsetOrMatches": 0
100-
},
101-
"upsertedCount": {
102-
"$$unsetOrMatches": 0
103-
},
104-
"matchedCount": {
105-
"$$unsetOrMatches": 0
106-
},
107-
"modifiedCount": {
108-
"$$unsetOrMatches": 0
109-
},
110-
"deletedCount": {
111-
"$$unsetOrMatches": 0
112-
},
113-
"insertResults": {
114-
"$$unsetOrMatches": {}
115-
},
116-
"updateResults": {
117-
"$$unsetOrMatches": {}
118-
},
119-
"deleteResults": {
120-
"$$unsetOrMatches": {}
98+
"$$unsetOrMatches": {
99+
"acknowledged": {
100+
"$$unsetOrMatches": false
101+
},
102+
"insertedCount": {
103+
"$$unsetOrMatches": 0
104+
},
105+
"upsertedCount": {
106+
"$$unsetOrMatches": 0
107+
},
108+
"matchedCount": {
109+
"$$unsetOrMatches": 0
110+
},
111+
"modifiedCount": {
112+
"$$unsetOrMatches": 0
113+
},
114+
"deletedCount": {
115+
"$$unsetOrMatches": 0
116+
},
117+
"insertResults": {
118+
"$$unsetOrMatches": {}
119+
},
120+
"updateResults": {
121+
"$$unsetOrMatches": {}
122+
},
123+
"deleteResults": {
124+
"$$unsetOrMatches": {}
125+
}
121126
}
122127
}
123128
},
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"description": "bulkWrite-updateMany-pipeline",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.1.11"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0",
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "crud-tests"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "test"
30+
}
31+
}
32+
],
33+
"initialData": [
34+
{
35+
"collectionName": "test",
36+
"databaseName": "crud-tests",
37+
"documents": [
38+
{
39+
"_id": 1,
40+
"x": 1,
41+
"y": 1,
42+
"t": {
43+
"u": {
44+
"v": 1
45+
}
46+
}
47+
},
48+
{
49+
"_id": 2,
50+
"x": 2,
51+
"y": 1
52+
}
53+
]
54+
}
55+
],
56+
"tests": [
57+
{
58+
"description": "UpdateMany in bulk write using pipelines",
59+
"operations": [
60+
{
61+
"object": "collection0",
62+
"name": "bulkWrite",
63+
"arguments": {
64+
"requests": [
65+
{
66+
"updateMany": {
67+
"filter": {},
68+
"update": [
69+
{
70+
"$project": {
71+
"x": 1
72+
}
73+
},
74+
{
75+
"$addFields": {
76+
"foo": 1
77+
}
78+
}
79+
]
80+
}
81+
}
82+
]
83+
},
84+
"expectResult": {
85+
"matchedCount": 2,
86+
"modifiedCount": 2,
87+
"upsertedCount": 0
88+
}
89+
}
90+
],
91+
"expectEvents": [
92+
{
93+
"client": "client0",
94+
"events": [
95+
{
96+
"commandStartedEvent": {
97+
"command": {
98+
"update": "test",
99+
"updates": [
100+
{
101+
"q": {},
102+
"u": [
103+
{
104+
"$project": {
105+
"x": 1
106+
}
107+
},
108+
{
109+
"$addFields": {
110+
"foo": 1
111+
}
112+
}
113+
],
114+
"multi": true,
115+
"upsert": {
116+
"$$unsetOrMatches": false
117+
}
118+
}
119+
]
120+
},
121+
"commandName": "update",
122+
"databaseName": "crud-tests"
123+
}
124+
}
125+
]
126+
}
127+
],
128+
"outcome": [
129+
{
130+
"collectionName": "test",
131+
"databaseName": "crud-tests",
132+
"documents": [
133+
{
134+
"_id": 1,
135+
"x": 1,
136+
"foo": 1
137+
},
138+
{
139+
"_id": 2,
140+
"x": 2,
141+
"foo": 1
142+
}
143+
]
144+
}
145+
]
146+
}
147+
]
148+
}

0 commit comments

Comments
 (0)