Skip to content

Commit ef761ea

Browse files
authored
CSHARP-5388: Allow drivers to set bypassDocumentValidation: false on write commands (#1736)
1 parent 676dd23 commit ef761ea

10 files changed

+747
-0
lines changed

specifications/crud/tests/unified/bypassDocumentValidation.json

Lines changed: 493 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
description: bypassDocumentValidation
2+
3+
schemaVersion: '1.4'
4+
5+
runOnRequirements:
6+
-
7+
minServerVersion: '3.2'
8+
serverless: forbid
9+
10+
createEntities:
11+
-
12+
client:
13+
id: &client0 client0
14+
observeEvents: [ commandStartedEvent ]
15+
-
16+
database:
17+
id: &database0 database0
18+
client: client0
19+
databaseName: &database_name crud
20+
-
21+
collection:
22+
id: &collection0 collection0
23+
database: database0
24+
collectionName: &collection_name coll
25+
26+
initialData:
27+
-
28+
collectionName: *collection_name
29+
databaseName: *database_name
30+
documents:
31+
- { _id: 1, x: 11 }
32+
- { _id: 2, x: 22 }
33+
- { _id: 3, x: 33 }
34+
35+
tests:
36+
-
37+
description: 'Aggregate with $out passes bypassDocumentValidation: false'
38+
operations:
39+
-
40+
object: *collection0
41+
name: aggregate
42+
arguments:
43+
pipeline: &pipeline
44+
- { $sort: { x: 1 } }
45+
- { $match: { _id: { $gt: 1 } } }
46+
- { $out: other_test_collection }
47+
bypassDocumentValidation: false
48+
expectEvents:
49+
- client: *client0
50+
events:
51+
- commandStartedEvent:
52+
command:
53+
aggregate: *collection_name
54+
pipeline: *pipeline
55+
bypassDocumentValidation: false
56+
commandName: aggregate
57+
databaseName: *database_name
58+
-
59+
description: 'BulkWrite passes bypassDocumentValidation: false'
60+
operations:
61+
-
62+
object: *collection0
63+
name: bulkWrite
64+
arguments:
65+
requests:
66+
-
67+
insertOne:
68+
document: &inserted_document { _id: 4, x: 44 }
69+
bypassDocumentValidation: false
70+
expectEvents:
71+
- client: *client0
72+
events:
73+
- commandStartedEvent:
74+
command:
75+
insert: *collection_name
76+
documents:
77+
- *inserted_document
78+
bypassDocumentValidation: false
79+
-
80+
description: 'FindOneAndReplace passes bypassDocumentValidation: false'
81+
operations:
82+
-
83+
object: *collection0
84+
name: findOneAndReplace
85+
arguments:
86+
filter: &filter { _id: { $gt: 1 } }
87+
replacement: &replacement { x: 32 }
88+
bypassDocumentValidation: false
89+
expectEvents:
90+
- client: *client0
91+
events:
92+
- commandStartedEvent:
93+
command:
94+
findAndModify: *collection_name
95+
query: *filter
96+
update: *replacement
97+
bypassDocumentValidation: false
98+
-
99+
description: 'FindOneAndUpdate passes bypassDocumentValidation: false'
100+
operations:
101+
-
102+
object: *collection0
103+
name: findOneAndUpdate
104+
arguments:
105+
filter: *filter
106+
update: &update { $inc: { x: 1 } }
107+
bypassDocumentValidation: false
108+
expectEvents:
109+
- client: *client0
110+
events:
111+
- commandStartedEvent:
112+
command:
113+
findAndModify: *collection_name
114+
query: *filter
115+
update: *update
116+
bypassDocumentValidation: false
117+
-
118+
description: 'InsertMany passes bypassDocumentValidation: false'
119+
operations:
120+
-
121+
object: *collection0
122+
name: insertMany
123+
arguments:
124+
documents:
125+
- *inserted_document
126+
bypassDocumentValidation: false
127+
expectEvents:
128+
- client: *client0
129+
events:
130+
- commandStartedEvent:
131+
command:
132+
insert: *collection_name
133+
documents:
134+
- *inserted_document
135+
bypassDocumentValidation: false
136+
-
137+
description: 'InsertOne passes bypassDocumentValidation: false'
138+
operations:
139+
-
140+
object: *collection0
141+
name: insertOne
142+
arguments:
143+
document: *inserted_document
144+
bypassDocumentValidation: false
145+
expectEvents:
146+
- client: *client0
147+
events:
148+
- commandStartedEvent:
149+
command:
150+
insert: *collection_name
151+
documents:
152+
- *inserted_document
153+
bypassDocumentValidation: false
154+
-
155+
description: 'ReplaceOne passes bypassDocumentValidation: false'
156+
operations:
157+
-
158+
object: *collection0
159+
name: replaceOne
160+
arguments:
161+
filter: *filter
162+
replacement: *replacement
163+
bypassDocumentValidation: false
164+
expectEvents:
165+
- client: *client0
166+
events:
167+
- commandStartedEvent:
168+
command:
169+
update: *collection_name
170+
updates:
171+
-
172+
q: *filter
173+
u: *replacement
174+
multi: { $$unsetOrMatches: false }
175+
upsert: { $$unsetOrMatches: false }
176+
bypassDocumentValidation: false
177+
-
178+
description: 'UpdateMany passes bypassDocumentValidation: false'
179+
operations:
180+
-
181+
object: *collection0
182+
name: updateMany
183+
arguments:
184+
filter: *filter
185+
update: *update
186+
bypassDocumentValidation: false
187+
expectEvents:
188+
- client: *client0
189+
events:
190+
- commandStartedEvent:
191+
command:
192+
update: *collection_name
193+
updates:
194+
-
195+
q: *filter
196+
u: *update
197+
multi: true
198+
upsert: { $$unsetOrMatches: false }
199+
bypassDocumentValidation: false
200+
-
201+
description: 'UpdateOne passes bypassDocumentValidation: false'
202+
operations:
203+
-
204+
object: *collection0
205+
name: updateOne
206+
arguments:
207+
filter: *filter
208+
update: *update
209+
bypassDocumentValidation: false
210+
expectEvents:
211+
- client: *client0
212+
events:
213+
- commandStartedEvent:
214+
command:
215+
update: *collection_name
216+
updates:
217+
-
218+
q: *filter
219+
u: *update
220+
multi: { $$unsetOrMatches: false }
221+
upsert: { $$unsetOrMatches: false }
222+
bypassDocumentValidation: false

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedAggregateOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ private IUnifiedEntityTestOperation Build(IMongoDatabase database, IMongoCollect
188188
options ??= new AggregateOptions();
189189
options.BatchSize = argument.Value.ToInt32();
190190
break;
191+
case "bypassDocumentValidation":
192+
options ??= new AggregateOptions();
193+
options.BypassDocumentValidation = argument.Value.AsBoolean;
194+
break;
191195
case "comment":
192196
options ??= new AggregateOptions();
193197
options.Comment = argument.Value;

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedBulkWriteOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public UnifiedBulkWriteOperation Build(string targetCollectionId, BsonDocument a
107107
{
108108
switch (argument.Name)
109109
{
110+
case "bypassDocumentValidation":
111+
options ??= new();
112+
options.BypassDocumentValidation = argument.Value.AsBoolean;
113+
break;
110114
case "comment":
111115
options ??= new BulkWriteOptions();
112116
options.Comment = argument.Value;

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedFindOneAndReplaceOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public UnifiedFindOneAndReplaceOperation Build(string targetCollectionId, BsonDo
9797
{
9898
switch (argument.Name)
9999
{
100+
case "bypassDocumentValidation":
101+
options ??= new();
102+
options.BypassDocumentValidation = argument.Value.AsBoolean;
103+
break;
100104
case "comment":
101105
options ??= new FindOneAndReplaceOptions<BsonDocument>();
102106
options.Comment = argument.Value;

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedFindOneAndUpdateOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public UnifiedFindOneAndUpdateOperation Build(string targetCollectionId, BsonDoc
9898
{
9999
switch (argument.Name)
100100
{
101+
case "bypassDocumentValidation":
102+
options ??= new();
103+
options.BypassDocumentValidation = argument.Value.AsBoolean;
104+
break;
101105
case "comment":
102106
options ??= new FindOneAndUpdateOptions<BsonDocument>();
103107
options.Comment = argument.Value;

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedInsertManyOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public UnifiedInsertManyOperation Build(string targetCollectionId, BsonDocument
105105
{
106106
switch (argument.Name)
107107
{
108+
case "bypassDocumentValidation":
109+
options ??= new();
110+
options.BypassDocumentValidation = argument.Value.AsBoolean;
111+
break;
108112
case "comment":
109113
options ??= new InsertManyOptions();
110114
options.Comment = argument.Value;

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedReplaceOneOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public UnifiedReplaceOneOperation Build(string targetCollectionId, BsonDocument
9797
{
9898
switch (argument.Name)
9999
{
100+
case "bypassDocumentValidation":
101+
options ??= new();
102+
options.BypassDocumentValidation = argument.Value.AsBoolean;
103+
break;
100104
case "comment":
101105
options ??= new ReplaceOptions<BsonDocument>();
102106
options.Comment = argument.Value;

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedUpdateManyOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public UnifiedUpdateManyOperation Build(string targetCollectionId, BsonDocument
112112
{
113113
switch (argument.Name)
114114
{
115+
case "bypassDocumentValidation":
116+
options ??= new();
117+
options.BypassDocumentValidation = argument.Value.AsBoolean;
118+
break;
115119
case "comment":
116120
options ??= new UpdateOptions();
117121
options.Comment = argument.Value;

tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedUpdateOneOperation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public UnifiedUpdateOneOperation Build(string targetCollectionId, BsonDocument a
112112
{
113113
switch (argument.Name)
114114
{
115+
case "bypassDocumentValidation":
116+
options ??= new();
117+
options.BypassDocumentValidation = argument.Value.AsBoolean;
118+
break;
115119
case "comment":
116120
options ??= new UpdateOptions<BsonDocument>();
117121
options.Comment = argument.Value;

0 commit comments

Comments
 (0)