Skip to content

Commit 5c65c07

Browse files
committed
feat(NODE-6329): client bulk write happy path
1 parent 6d65ae7 commit 5c65c07

File tree

15 files changed

+2068
-5
lines changed

15 files changed

+2068
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { AbstractCursor } from './abstract_cursor';
2+
3+
export class ClientBulkWriteCursor extends AbstractCursor {
4+
5+
}

src/mongo_client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
475475
return this.s.bsonOptions;
476476
}
477477

478+
async bulkWrite(): Promise<ClientBulkWriteResult> {
479+
480+
}
481+
478482
/**
479483
* Connect to MongoDB using a url
480484
*
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { AbstractOperation } from '../operation';
2+
3+
export interface ClientBulkWriteResult {
4+
/**
5+
* The total number of documents inserted across all insert operations.
6+
*/
7+
insertedCount: number;
8+
/**
9+
* The total number of documents upserted across all update operations.
10+
*/
11+
upsertedCount: number;
12+
/**
13+
* The total number of documents matched across all update operations.
14+
*/
15+
matchedCount: number;
16+
/**
17+
* The total number of documents modified across all update operations.
18+
*/
19+
modifiedCount: number;
20+
/**
21+
* The total number of documents deleted across all delete operations.
22+
*/
23+
deletedCount: number;
24+
}
25+
26+
export interface VerboseClientBulkWriteResult extends ClientBulkWriteResult {
27+
/**
28+
* The results of each individual insert operation that was successfully performed.
29+
*/
30+
insertResults: Map<number, ClientInsertOneResult>;
31+
/**
32+
* The results of each individual update operation that was successfully performed.
33+
*/
34+
updateResults: Map<number, ClientUpdateResult>;
35+
/**
36+
* The results of each individual delete operation that was successfully performed.
37+
*/
38+
deleteResults: Map<number, ClientDeleteResult>;
39+
}
40+
41+
export interface ClientInsertOneResult {
42+
/**
43+
* The _id of the inserted document.
44+
*/
45+
insertedId: any;
46+
}
47+
48+
export interface ClientUpdateResult {
49+
/**
50+
* The number of documents that matched the filter.
51+
*/
52+
matchedCount: number;
53+
54+
/**
55+
* The number of documents that were modified.
56+
*/
57+
modifiedCount: number;
58+
59+
/**
60+
* The _id field of the upserted document if an upsert occurred.
61+
*
62+
* It MUST be possible to discern between a BSON Null upserted ID value and this field being
63+
* unset. If necessary, drivers MAY add a didUpsert boolean field to differentiate between
64+
* these two cases.
65+
*/
66+
upsertedId?: any;
67+
}
68+
69+
export interface ClientDeleteResult {
70+
/**
71+
* The number of documents that were deleted.
72+
*/
73+
deletedCount: number;
74+
}
75+
76+
export class ClientBulkWriteOperation extends AbstractOperation<ClientBulkWriteResult> {
77+
}

test/integration/crud/crud.spec.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
55

66
const clientBulkWriteTests = new RegExp(
77
[
8-
'client bulk write delete with collation',
9-
'client bulk write delete with hint',
108
'client bulkWrite operations support errorResponse assertions',
119
'an individual operation fails during an ordered bulkWrite',
1210
'an individual operation fails during an unordered bulkWrite',
1311
'detailed results are omitted from error when verboseResults is false',
1412
'a top-level failure occurs during a bulkWrite',
1513
'a bulk write with only errors does not report a partial result',
1614
'an empty list of write models is a client-side error',
17-
'a write concern error occurs during a bulkWrite',
18-
'client bulkWrite'
15+
'a write concern error occurs during a bulkWrite'
1916
].join('|')
2017
);
2118

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
{
2+
"description": "unacknowledged-client-bulkWrite",
3+
"schemaVersion": "1.7",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "8.0"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client",
13+
"useMultipleMongoses": false,
14+
"observeEvents": [
15+
"commandStartedEvent",
16+
"commandSucceededEvent",
17+
"commandFailedEvent"
18+
],
19+
"uriOptions": {
20+
"w": 0
21+
}
22+
}
23+
},
24+
{
25+
"database": {
26+
"id": "database",
27+
"client": "client",
28+
"databaseName": "command-monitoring-tests"
29+
}
30+
},
31+
{
32+
"collection": {
33+
"id": "collection",
34+
"database": "database",
35+
"collectionName": "test"
36+
}
37+
}
38+
],
39+
"initialData": [
40+
{
41+
"collectionName": "test",
42+
"databaseName": "command-monitoring-tests",
43+
"documents": [
44+
{
45+
"_id": 1,
46+
"x": 11
47+
},
48+
{
49+
"_id": 2,
50+
"x": 22
51+
},
52+
{
53+
"_id": 3,
54+
"x": 33
55+
}
56+
]
57+
}
58+
],
59+
"_yamlAnchors": {
60+
"namespace": "command-monitoring-tests.test"
61+
},
62+
"tests": [
63+
{
64+
"description": "A successful mixed client bulkWrite",
65+
"operations": [
66+
{
67+
"object": "client",
68+
"name": "clientBulkWrite",
69+
"arguments": {
70+
"models": [
71+
{
72+
"insertOne": {
73+
"namespace": "command-monitoring-tests.test",
74+
"document": {
75+
"_id": 4,
76+
"x": 44
77+
}
78+
}
79+
},
80+
{
81+
"updateOne": {
82+
"namespace": "command-monitoring-tests.test",
83+
"filter": {
84+
"_id": 3
85+
},
86+
"update": {
87+
"$set": {
88+
"x": 333
89+
}
90+
}
91+
}
92+
}
93+
]
94+
},
95+
"expectResult": {
96+
"insertedCount": {
97+
"$$unsetOrMatches": 0
98+
},
99+
"upsertedCount": {
100+
"$$unsetOrMatches": 0
101+
},
102+
"matchedCount": {
103+
"$$unsetOrMatches": 0
104+
},
105+
"modifiedCount": {
106+
"$$unsetOrMatches": 0
107+
},
108+
"deletedCount": {
109+
"$$unsetOrMatches": 0
110+
},
111+
"insertResults": {
112+
"$$unsetOrMatches": {}
113+
},
114+
"updateResults": {
115+
"$$unsetOrMatches": {}
116+
},
117+
"deleteResults": {
118+
"$$unsetOrMatches": {}
119+
}
120+
}
121+
},
122+
{
123+
"object": "collection",
124+
"name": "find",
125+
"arguments": {
126+
"filter": {}
127+
},
128+
"expectResult": [
129+
{
130+
"_id": 1,
131+
"x": 11
132+
},
133+
{
134+
"_id": 2,
135+
"x": 22
136+
},
137+
{
138+
"_id": 3,
139+
"x": 333
140+
},
141+
{
142+
"_id": 4,
143+
"x": 44
144+
}
145+
]
146+
}
147+
],
148+
"expectEvents": [
149+
{
150+
"client": "client",
151+
"ignoreExtraEvents": true,
152+
"events": [
153+
{
154+
"commandStartedEvent": {
155+
"commandName": "bulkWrite",
156+
"databaseName": "admin",
157+
"command": {
158+
"bulkWrite": 1,
159+
"errorsOnly": true,
160+
"ordered": true,
161+
"ops": [
162+
{
163+
"insert": 0,
164+
"document": {
165+
"_id": 4,
166+
"x": 44
167+
}
168+
},
169+
{
170+
"update": 0,
171+
"filter": {
172+
"_id": 3
173+
},
174+
"updateMods": {
175+
"$set": {
176+
"x": 333
177+
}
178+
},
179+
"multi": false
180+
}
181+
],
182+
"nsInfo": [
183+
{
184+
"ns": "command-monitoring-tests.test"
185+
}
186+
]
187+
}
188+
}
189+
},
190+
{
191+
"commandSucceededEvent": {
192+
"commandName": "bulkWrite",
193+
"reply": {
194+
"ok": 1,
195+
"nInserted": {
196+
"$$exists": false
197+
},
198+
"nMatched": {
199+
"$$exists": false
200+
},
201+
"nModified": {
202+
"$$exists": false
203+
},
204+
"nUpserted": {
205+
"$$exists": false
206+
},
207+
"nDeleted": {
208+
"$$exists": false
209+
}
210+
}
211+
}
212+
}
213+
]
214+
}
215+
]
216+
}
217+
]
218+
}

0 commit comments

Comments
 (0)