Skip to content

Commit 6f633d1

Browse files
feat(NODE-4014): Add let option to bulk write operations (#3160)
1 parent 6e2661b commit 6f633d1

20 files changed

+1579
-18
lines changed

docs/Next/assets/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Next/classes/BulkOperationBase.html

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/Next/classes/OrderedBulkOperation.html

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/Next/classes/UnorderedBulkOperation.html

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/Next/interfaces/BulkWriteOptions.html

Lines changed: 5 additions & 3 deletions
Large diffs are not rendered by default.

docs/img/gray.png

-19.4 KB
Binary file not shown.

docs/img/logo-mongodb-header.png

-17.4 KB
Binary file not shown.

src/bulk/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ export interface BulkWriteOptions extends CommandOperationOptions {
919919
keepGoing?: boolean;
920920
/** Force server to assign _id values instead of driver. */
921921
forceServerObjectId?: boolean;
922+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
923+
let?: Document;
922924
}
923925

924926
/**
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
{
2+
"description": "BulkWrite deleteMany-let",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"observeEvents": [
9+
"commandStartedEvent"
10+
]
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database0",
16+
"client": "client0",
17+
"databaseName": "crud-tests"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection0",
23+
"database": "database0",
24+
"collectionName": "coll0"
25+
}
26+
}
27+
],
28+
"initialData": [
29+
{
30+
"collectionName": "coll0",
31+
"databaseName": "crud-tests",
32+
"documents": [
33+
{
34+
"_id": 1
35+
},
36+
{
37+
"_id": 2
38+
}
39+
]
40+
}
41+
],
42+
"tests": [
43+
{
44+
"description": "BulkWrite deleteMany with let option",
45+
"runOnRequirements": [
46+
{
47+
"minServerVersion": "5.0"
48+
}
49+
],
50+
"operations": [
51+
{
52+
"object": "collection0",
53+
"name": "bulkWrite",
54+
"arguments": {
55+
"requests": [
56+
{
57+
"deleteMany": {
58+
"filter": {
59+
"$expr": {
60+
"$eq": [
61+
"$_id",
62+
"$$id"
63+
]
64+
}
65+
}
66+
}
67+
}
68+
],
69+
"let": {
70+
"id": 1
71+
}
72+
}
73+
}
74+
],
75+
"expectEvents": [
76+
{
77+
"client": "client0",
78+
"events": [
79+
{
80+
"commandStartedEvent": {
81+
"command": {
82+
"delete": "coll0",
83+
"deletes": [
84+
{
85+
"q": {
86+
"$expr": {
87+
"$eq": [
88+
"$_id",
89+
"$$id"
90+
]
91+
}
92+
},
93+
"limit": 0
94+
}
95+
],
96+
"let": {
97+
"id": 1
98+
}
99+
}
100+
}
101+
}
102+
]
103+
}
104+
],
105+
"outcome": [
106+
{
107+
"collectionName": "coll0",
108+
"databaseName": "crud-tests",
109+
"documents": [
110+
{
111+
"_id": 2
112+
}
113+
]
114+
}
115+
]
116+
},
117+
{
118+
"description": "BulkWrite deleteMany with let option unsupported (server-side error)",
119+
"runOnRequirements": [
120+
{
121+
"minServerVersion": "3.6.0",
122+
"maxServerVersion": "4.4.99"
123+
}
124+
],
125+
"operations": [
126+
{
127+
"object": "collection0",
128+
"name": "bulkWrite",
129+
"arguments": {
130+
"requests": [
131+
{
132+
"deleteOne": {
133+
"filter": {
134+
"$expr": {
135+
"$eq": [
136+
"$_id",
137+
"$$id"
138+
]
139+
}
140+
}
141+
}
142+
}
143+
],
144+
"let": {
145+
"id": 1
146+
}
147+
},
148+
"expectError": {
149+
"errorContains": "'delete.let' is an unknown field",
150+
"isClientError": false
151+
}
152+
}
153+
],
154+
"expectEvents": [
155+
{
156+
"client": "client0",
157+
"events": [
158+
{
159+
"commandStartedEvent": {
160+
"command": {
161+
"delete": "coll0",
162+
"deletes": [
163+
{
164+
"q": {
165+
"$expr": {
166+
"$eq": [
167+
"$_id",
168+
"$$id"
169+
]
170+
}
171+
},
172+
"limit": 1
173+
}
174+
],
175+
"let": {
176+
"id": 1
177+
}
178+
}
179+
}
180+
}
181+
]
182+
}
183+
],
184+
"outcome": [
185+
{
186+
"collectionName": "coll0",
187+
"databaseName": "crud-tests",
188+
"documents": [
189+
{
190+
"_id": 1
191+
},
192+
{
193+
"_id": 2
194+
}
195+
]
196+
}
197+
]
198+
}
199+
]
200+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
description: "BulkWrite deleteMany-let"
2+
3+
schemaVersion: "1.0"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
observeEvents: [ commandStartedEvent ]
9+
- database:
10+
id: &database0 database0
11+
client: *client0
12+
databaseName: &database0Name crud-tests
13+
- collection:
14+
id: &collection0 collection0
15+
database: *database0
16+
collectionName: &collection0Name coll0
17+
18+
initialData:
19+
- collectionName: *collection0Name
20+
databaseName: *database0Name
21+
documents:
22+
- { _id: 1 }
23+
- { _id: 2 }
24+
25+
tests:
26+
- description: "BulkWrite deleteMany with let option"
27+
runOnRequirements:
28+
- minServerVersion: "5.0"
29+
operations:
30+
- object: *collection0
31+
name: bulkWrite
32+
arguments:
33+
requests:
34+
- deleteMany:
35+
filter: &filter
36+
$expr:
37+
$eq: [ "$_id", "$$id" ]
38+
let: &let
39+
id: 1
40+
expectEvents:
41+
- client: *client0
42+
events:
43+
- commandStartedEvent:
44+
command:
45+
delete: *collection0Name
46+
deletes:
47+
- q: *filter
48+
limit: 0
49+
let: *let
50+
outcome:
51+
- collectionName: *collection0Name
52+
databaseName: *database0Name
53+
documents:
54+
- { _id: 2 }
55+
56+
- description: "BulkWrite deleteMany with let option unsupported (server-side error)"
57+
runOnRequirements:
58+
- minServerVersion: "3.6.0"
59+
maxServerVersion: "4.4.99"
60+
operations:
61+
- object: *collection0
62+
name: bulkWrite
63+
arguments:
64+
requests:
65+
- deleteOne:
66+
filter: *filter
67+
let: *let
68+
expectError:
69+
errorContains: "'delete.let' is an unknown field"
70+
isClientError: false
71+
expectEvents:
72+
- client: *client0
73+
events:
74+
- commandStartedEvent:
75+
command:
76+
delete: *collection0Name
77+
deletes:
78+
- q: *filter
79+
limit: 1
80+
let: *let
81+
outcome:
82+
- collectionName: *collection0Name
83+
databaseName: *database0Name
84+
documents:
85+
- { _id: 1 }
86+
- { _id: 2 }

0 commit comments

Comments
 (0)