Skip to content

Commit 60adafc

Browse files
committed
SPEC-1334: Hint option for update commands
1 parent aeb52a4 commit 60adafc

9 files changed

+1066
-1
lines changed

source/crud/crud.rst

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Driver CRUD API
1212
:Status: Approved
1313
:Type: Standards
1414
:Minimum Server Version: 2.6
15-
:Last Modified: February 20, 2019
15+
:Last Modified: September 26, 2019
1616

1717
.. contents::
1818

@@ -884,6 +884,17 @@ Basic
884884
*/
885885
collation: Optional<Document>;
886886
887+
/**
888+
* The index to use.
889+
*
890+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
891+
* This option is only supported by servers >= 4.2. Older servers >= 3.4 will report an error for using this option.
892+
* For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value.
893+
*
894+
* @see https://docs.mongodb.com/manual/reference/command/update/
895+
*/
896+
hint: Optional<(String | Document)>;
897+
887898
/**
888899
* When true, creates a new document if no document matches the query.
889900
*
@@ -916,6 +927,17 @@ Basic
916927
*/
917928
collation: Optional<Document>;
918929
930+
/**
931+
* The index to use.
932+
*
933+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
934+
* This option is only supported by servers >= 4.2. Older servers >= 3.4 will report an error for using this option.
935+
* For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value.
936+
*
937+
* @see https://docs.mongodb.com/manual/reference/command/update/
938+
*/
939+
hint: Optional<(String | Document)>;
940+
919941
/**
920942
* When true, creates a new document if no document matches the query.
921943
*
@@ -1029,6 +1051,17 @@ Bulk Write Models
10291051
*/
10301052
collation: Optional<Document>;
10311053
1054+
/**
1055+
* The index to use.
1056+
*
1057+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
1058+
* This option is only supported by servers >= 4.2. Older servers >= 3.4 will report an error for using this option.
1059+
* For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value.
1060+
*
1061+
* @see https://docs.mongodb.com/manual/reference/command/update/
1062+
*/
1063+
hint: Optional<(String | Document)>;
1064+
10321065
/**
10331066
* When true, creates a new document if no document matches the query.
10341067
*
@@ -1077,6 +1110,17 @@ Bulk Write Models
10771110
*/
10781111
collation: Optional<Document>;
10791112
1113+
/**
1114+
* The index to use.
1115+
*
1116+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
1117+
* This option is only supported by servers >= 4.2. Older servers >= 3.4 will report an error for using this option.
1118+
* For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value.
1119+
*
1120+
* @see https://docs.mongodb.com/manual/reference/command/update/
1121+
*/
1122+
hint: Optional<(String | Document)>;
1123+
10801124
/**
10811125
* When true, creates a new document if no document matches the query.
10821126
*
@@ -1125,6 +1169,17 @@ Bulk Write Models
11251169
*/
11261170
collation: Optional<Document>;
11271171
1172+
/**
1173+
* The index to use.
1174+
*
1175+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
1176+
* This option is only supported by servers >= 4.2. Older servers >= 3.4 will report an error for using this option.
1177+
* For servers < 3.4, the driver MUST raise an error if the caller explicitly provides a value.
1178+
*
1179+
* @see https://docs.mongodb.com/manual/reference/command/update/
1180+
*/
1181+
hint: Optional<(String | Document)>;
1182+
11281183
/**
11291184
* When true, creates a new document if no document matches the query.
11301185
*
@@ -1766,6 +1821,7 @@ Q: Where is ``singleBatch`` in FindOptions?
17661821
Changes
17671822
=======
17681823

1824+
* 2019-09-26: Added hint option for update commands.
17691825
* 2019-06-07: Consistent treatment for aggregate $merge and $out stages
17701826
* 2019-05-01: Specify a document or pipeline for commands with updates in server 4.2+.
17711827
* 2019-02-20: Mark the `request` field of `BulkWriteError` as NOT REQUIRED
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.2.0"
5+
}
6+
],
7+
"data": [
8+
{
9+
"_id": 1,
10+
"x": 11
11+
},
12+
{
13+
"_id": 2,
14+
"x": 22
15+
},
16+
{
17+
"_id": 3,
18+
"x": 33
19+
},
20+
{
21+
"_id": 4,
22+
"x": 44
23+
}
24+
],
25+
"collection_name": "test_bulkwrite_update_hint",
26+
"tests": [
27+
{
28+
"description": "BulkWrite with update hints",
29+
"operations": [
30+
{
31+
"name": "bulkWrite",
32+
"arguments": {
33+
"requests": [
34+
{
35+
"name": "updateOne",
36+
"arguments": {
37+
"filter": {
38+
"_id": 1
39+
},
40+
"update": {
41+
"$inc": {
42+
"x": 1
43+
}
44+
},
45+
"hint": "_id_"
46+
}
47+
},
48+
{
49+
"name": "updateOne",
50+
"arguments": {
51+
"filter": {
52+
"_id": 1
53+
},
54+
"update": {
55+
"$inc": {
56+
"x": 1
57+
}
58+
},
59+
"hint": {
60+
"_id": 1
61+
}
62+
}
63+
},
64+
{
65+
"name": "updateMany",
66+
"arguments": {
67+
"filter": {
68+
"_id": {
69+
"$lt": 3
70+
}
71+
},
72+
"update": {
73+
"$inc": {
74+
"x": 1
75+
}
76+
},
77+
"hint": "_id_"
78+
}
79+
},
80+
{
81+
"name": "updateMany",
82+
"arguments": {
83+
"filter": {
84+
"_id": {
85+
"$lt": 3
86+
}
87+
},
88+
"update": {
89+
"$inc": {
90+
"x": 1
91+
}
92+
},
93+
"hint": {
94+
"_id": 1
95+
}
96+
}
97+
},
98+
{
99+
"name": "replaceOne",
100+
"arguments": {
101+
"filter": {
102+
"_id": 3
103+
},
104+
"replacement": {
105+
"x": 333
106+
},
107+
"hint": "_id_"
108+
}
109+
},
110+
{
111+
"name": "replaceOne",
112+
"arguments": {
113+
"filter": {
114+
"_id": 4
115+
},
116+
"replacement": {
117+
"x": 444
118+
},
119+
"hint": {
120+
"_id": 1
121+
}
122+
}
123+
}
124+
],
125+
"options": {
126+
"ordered": true
127+
}
128+
},
129+
"result": {
130+
"deletedCount": 0,
131+
"insertedCount": 0,
132+
"insertedIds": {},
133+
"matchedCount": 8,
134+
"modifiedCount": 8,
135+
"upsertedCount": 0,
136+
"upsertedIds": {}
137+
}
138+
}
139+
],
140+
"expectations": [
141+
{
142+
"command_started_event": {
143+
"command": {
144+
"update": "test_bulkwrite_update_hint",
145+
"updates": [
146+
{
147+
"q": {
148+
"_id": 1
149+
},
150+
"u": {
151+
"$inc": {
152+
"x": 1
153+
}
154+
},
155+
"hint": "_id_"
156+
},
157+
{
158+
"q": {
159+
"_id": 1
160+
},
161+
"u": {
162+
"$inc": {
163+
"x": 1
164+
}
165+
},
166+
"hint": {
167+
"_id": 1
168+
}
169+
},
170+
{
171+
"q": {
172+
"_id": {
173+
"$lt": 3
174+
}
175+
},
176+
"u": {
177+
"$inc": {
178+
"x": 1
179+
}
180+
},
181+
"multi": true,
182+
"hint": "_id_"
183+
},
184+
{
185+
"q": {
186+
"_id": {
187+
"$lt": 3
188+
}
189+
},
190+
"u": {
191+
"$inc": {
192+
"x": 1
193+
}
194+
},
195+
"multi": true,
196+
"hint": {
197+
"_id": 1
198+
}
199+
},
200+
{
201+
"q": {
202+
"_id": 3
203+
},
204+
"u": {
205+
"x": 333
206+
},
207+
"hint": "_id_"
208+
},
209+
{
210+
"q": {
211+
"_id": 4
212+
},
213+
"u": {
214+
"x": 444
215+
},
216+
"hint": {
217+
"_id": 1
218+
}
219+
}
220+
],
221+
"ordered": true
222+
}
223+
}
224+
}
225+
],
226+
"outcome": {
227+
"collection": {
228+
"data": [
229+
{
230+
"_id": 1,
231+
"x": 15
232+
},
233+
{
234+
"_id": 2,
235+
"x": 24
236+
},
237+
{
238+
"_id": 3,
239+
"x": 333
240+
},
241+
{
242+
"_id": 4,
243+
"x": 444
244+
}
245+
]
246+
}
247+
}
248+
}
249+
]
250+
}

0 commit comments

Comments
 (0)