Skip to content

Commit 11b393e

Browse files
fix lint
1 parent 86368fe commit 11b393e

File tree

7 files changed

+1015
-4
lines changed

7 files changed

+1015
-4
lines changed

src/operations/update.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Document } from '../bson';
22
import type { Collection } from '../collection';
3-
import { MongoAPIError, MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } from '../error';
3+
import { MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } from '../error';
44
import type { InferIdType, TODO_NODE_3286 } from '../mongo_types';
55
import type { Server } from '../sdam/server';
66
import type { ClientSession } from '../sessions';
7-
import { formatSort, SortForCmd } from '../sort';
7+
import { formatSort } from '../sort';
88
import { hasAtomicOperators, type MongoDBNamespace } from '../utils';
99
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
1010
import { Aspect, defineAspects, type Hint } from './operation';
@@ -68,7 +68,7 @@ export interface UpdateStatement {
6868
/** A document or string that specifies the index to use to support the query predicate. */
6969
hint?: Hint;
7070
/** If the query matches multiple documents, the first document matched by the sort order will be updated. */
71-
sort?: SortForCmd;
71+
sort?: Map<string, 1 | -1 | { $meta: string }>;
7272
}
7373

7474
/**
@@ -282,7 +282,7 @@ export function makeUpdateStatement(
282282
throw new MongoInvalidArgumentError('Document must be a valid JavaScript object');
283283
}
284284

285-
const op: UpdateOneStatement = { q: filter, u: update };
285+
const op: UpdateStatement = { q: filter, u: update };
286286
if (typeof options.upsert === 'boolean') {
287287
op.upsert = options.upsert;
288288
}
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
{
2+
"description": "BulkWrite updateOne-sort",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"observeEvents": [
9+
"commandStartedEvent",
10+
"commandSucceededEvent"
11+
]
12+
}
13+
},
14+
{
15+
"database": {
16+
"id": "database0",
17+
"client": "client0",
18+
"databaseName": "crud-tests"
19+
}
20+
},
21+
{
22+
"collection": {
23+
"id": "collection0",
24+
"database": "database0",
25+
"collectionName": "coll0"
26+
}
27+
}
28+
],
29+
"initialData": [
30+
{
31+
"collectionName": "coll0",
32+
"databaseName": "crud-tests",
33+
"documents": [
34+
{
35+
"_id": 1,
36+
"x": 11
37+
},
38+
{
39+
"_id": 2,
40+
"x": 22
41+
},
42+
{
43+
"_id": 3,
44+
"x": 33
45+
}
46+
]
47+
}
48+
],
49+
"tests": [
50+
{
51+
"description": "BulkWrite updateOne with sort option",
52+
"runOnRequirements": [
53+
{
54+
"minServerVersion": "8.0"
55+
}
56+
],
57+
"operations": [
58+
{
59+
"object": "collection0",
60+
"name": "bulkWrite",
61+
"arguments": {
62+
"requests": [
63+
{
64+
"updateOne": {
65+
"filter": {
66+
"_id": {
67+
"$gt": 1
68+
}
69+
},
70+
"sort": {
71+
"_id": -1
72+
},
73+
"update": [
74+
{
75+
"$set": {
76+
"x": 1
77+
}
78+
}
79+
]
80+
}
81+
}
82+
]
83+
}
84+
}
85+
],
86+
"expectEvents": [
87+
{
88+
"client": "client0",
89+
"events": [
90+
{
91+
"commandStartedEvent": {
92+
"command": {
93+
"update": "coll0",
94+
"updates": [
95+
{
96+
"q": {
97+
"_id": {
98+
"$gt": 1
99+
}
100+
},
101+
"u": [
102+
{
103+
"$set": {
104+
"x": 1
105+
}
106+
}
107+
],
108+
"sort": {
109+
"_id": -1
110+
},
111+
"multi": {
112+
"$$unsetOrMatches": false
113+
},
114+
"upsert": {
115+
"$$unsetOrMatches": false
116+
}
117+
}
118+
]
119+
}
120+
}
121+
},
122+
{
123+
"commandSucceededEvent": {
124+
"reply": {
125+
"ok": 1,
126+
"n": 1
127+
},
128+
"commandName": "update"
129+
}
130+
}
131+
]
132+
}
133+
],
134+
"outcome": [
135+
{
136+
"collectionName": "coll0",
137+
"databaseName": "crud-tests",
138+
"documents": [
139+
{
140+
"_id": 1,
141+
"x": 11
142+
},
143+
{
144+
"_id": 2,
145+
"x": 22
146+
},
147+
{
148+
"_id": 3,
149+
"x": 1
150+
}
151+
]
152+
}
153+
]
154+
},
155+
{
156+
"description": "BulkWrite updateOne with sort option unsupported (server-side error)",
157+
"runOnRequirements": [
158+
{
159+
"maxServerVersion": "7.99"
160+
}
161+
],
162+
"operations": [
163+
{
164+
"object": "collection0",
165+
"name": "bulkWrite",
166+
"arguments": {
167+
"requests": [
168+
{
169+
"updateOne": {
170+
"filter": {
171+
"_id": {
172+
"$gt": 1
173+
}
174+
},
175+
"sort": {
176+
"_id": -1
177+
},
178+
"update": [
179+
{
180+
"$set": {
181+
"x": 1
182+
}
183+
}
184+
]
185+
}
186+
}
187+
]
188+
},
189+
"expectError": {
190+
"isClientError": false
191+
}
192+
}
193+
],
194+
"expectEvents": [
195+
{
196+
"client": "client0",
197+
"events": [
198+
{
199+
"commandStartedEvent": {
200+
"command": {
201+
"update": "coll0",
202+
"updates": [
203+
{
204+
"q": {
205+
"_id": {
206+
"$gt": 1
207+
}
208+
},
209+
"u": [
210+
{
211+
"$set": {
212+
"x": 1
213+
}
214+
}
215+
],
216+
"sort": {
217+
"_id": -1
218+
},
219+
"multi": {
220+
"$$unsetOrMatches": false
221+
},
222+
"upsert": {
223+
"$$unsetOrMatches": false
224+
}
225+
}
226+
]
227+
}
228+
}
229+
}
230+
]
231+
}
232+
],
233+
"outcome": [
234+
{
235+
"collectionName": "coll0",
236+
"databaseName": "crud-tests",
237+
"documents": [
238+
{
239+
"_id": 1,
240+
"x": 11
241+
},
242+
{
243+
"_id": 2,
244+
"x": 22
245+
},
246+
{
247+
"_id": 3,
248+
"x": 33
249+
}
250+
]
251+
}
252+
]
253+
}
254+
]
255+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
description: BulkWrite updateOne-sort
2+
3+
schemaVersion: "1.0"
4+
5+
createEntities:
6+
- client:
7+
id: client0
8+
observeEvents: [ commandStartedEvent, commandSucceededEvent ]
9+
- database:
10+
id: database0
11+
client: client0
12+
databaseName: crud-tests
13+
- collection:
14+
id: collection0
15+
database: database0
16+
collectionName: coll0
17+
18+
initialData:
19+
- collectionName: coll0
20+
databaseName: crud-tests
21+
documents:
22+
- { _id: 1, x: 11 }
23+
- { _id: 2, x: 22 }
24+
- { _id: 3, x: 33 }
25+
26+
tests:
27+
- description: BulkWrite updateOne with sort option
28+
runOnRequirements:
29+
- minServerVersion: "8.0"
30+
operations:
31+
- object: collection0
32+
name: bulkWrite
33+
arguments:
34+
requests:
35+
- updateOne:
36+
filter: { _id: { $gt: 1 } }
37+
sort: { _id: -1 }
38+
update: [ $set: { x: 1 } ]
39+
expectEvents:
40+
- client: client0
41+
events:
42+
- commandStartedEvent:
43+
command:
44+
update: coll0
45+
updates:
46+
- q: { _id: { $gt: 1 } }
47+
u: [ $set: { x: 1 } ]
48+
sort: { _id: -1 }
49+
multi: { $$unsetOrMatches: false }
50+
upsert: { $$unsetOrMatches: false }
51+
- commandSucceededEvent:
52+
reply: { ok: 1, n: 1 }
53+
commandName: update
54+
outcome:
55+
- collectionName: coll0
56+
databaseName: crud-tests
57+
documents:
58+
- { _id: 1, x: 11 }
59+
- { _id: 2, x: 22 }
60+
- { _id: 3, x: 1 }
61+
62+
- description: BulkWrite updateOne with sort option unsupported (server-side error)
63+
runOnRequirements:
64+
- maxServerVersion: "7.99"
65+
operations:
66+
- object: collection0
67+
name: bulkWrite
68+
arguments:
69+
requests:
70+
- updateOne:
71+
filter: { _id: { $gt: 1 } }
72+
sort: { _id: -1 }
73+
update: [ $set: { x: 1 } ]
74+
expectError:
75+
isClientError: false
76+
expectEvents:
77+
- client: client0
78+
events:
79+
- commandStartedEvent:
80+
command:
81+
update: coll0
82+
updates:
83+
- q: { _id: { $gt: 1 } }
84+
u: [ $set: { x: 1 } ]
85+
sort: { _id: -1 }
86+
multi: { $$unsetOrMatches: false }
87+
upsert: { $$unsetOrMatches: false }
88+
outcome:
89+
- collectionName: coll0
90+
databaseName: crud-tests
91+
documents:
92+
- { _id: 1, x: 11 }
93+
- { _id: 2, x: 22 }
94+
- { _id: 3, x: 33 }

0 commit comments

Comments
 (0)