@@ -19,6 +19,7 @@ import (
19
19
"go.mongodb.org/mongo-driver/v2/mongo"
20
20
"go.mongodb.org/mongo-driver/v2/mongo/options"
21
21
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
22
+ "go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions"
22
23
)
23
24
24
25
// This file contains helpers to execute collection operations.
@@ -75,6 +76,11 @@ func executeAggregate(ctx context.Context, operation *operation) (*operationResu
75
76
pipeline = bsonutil .RawToInterfaces (bsonutil .RawArrayToDocuments (val .Array ())... )
76
77
case "let" :
77
78
opts .SetLet (val .Document ())
79
+ case "rawData" :
80
+ err = xoptions .SetInternalAggregateOptions (opts , key , val .Boolean ())
81
+ if err != nil {
82
+ return nil , err
83
+ }
78
84
default :
79
85
return nil , fmt .Errorf ("unrecognized aggregate option %q" , key )
80
86
}
@@ -125,6 +131,11 @@ func executeBulkWrite(ctx context.Context, operation *operation) (*operationResu
125
131
}
126
132
case "let" :
127
133
opts .SetLet (val .Document ())
134
+ case "rawData" :
135
+ err = xoptions .SetInternalBulkWriteOptions (opts , key , val .Boolean ())
136
+ if err != nil {
137
+ return nil , err
138
+ }
128
139
default :
129
140
return nil , fmt .Errorf ("unrecognized bulkWrite option %q" , key )
130
141
}
@@ -202,6 +213,11 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio
202
213
return nil , fmt .Errorf ("the maxTimeMS collection option is not supported" )
203
214
case "skip" :
204
215
opts .SetSkip (int64 (val .Int32 ()))
216
+ case "rawData" :
217
+ err = xoptions .SetInternalCountOptions (opts , key , val .Boolean ())
218
+ if err != nil {
219
+ return nil , err
220
+ }
205
221
default :
206
222
return nil , fmt .Errorf ("unrecognized countDocuments option %q" , key )
207
223
}
@@ -225,6 +241,7 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
225
241
226
242
var keys bson.Raw
227
243
indexOpts := options .Index ()
244
+ opts := options .CreateIndexes ()
228
245
229
246
elems , err := operation .Arguments .Elements ()
230
247
if err != nil {
@@ -279,6 +296,11 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
279
296
indexOpts .SetWeights (val .Document ())
280
297
case "wildcardProjection" :
281
298
indexOpts .SetWildcardProjection (val .Document ())
299
+ case "rawData" :
300
+ err = xoptions .SetInternalCreateIndexesOptions (opts , key , val .Boolean ())
301
+ if err != nil {
302
+ return nil , err
303
+ }
282
304
default :
283
305
return nil , fmt .Errorf ("unrecognized createIndex option %q" , key )
284
306
}
@@ -291,7 +313,8 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
291
313
Keys : keys ,
292
314
Options : indexOpts ,
293
315
}
294
- name , err := coll .Indexes ().CreateOne (ctx , model )
316
+
317
+ name , err := coll .Indexes ().CreateOne (ctx , model , opts )
295
318
return newValueResult (bson .TypeString , bsoncore .AppendString (nil , name ), err ), nil
296
319
}
297
320
@@ -433,6 +456,11 @@ func executeDeleteOne(ctx context.Context, operation *operation) (*operationResu
433
456
opts .SetHint (hint )
434
457
case "let" :
435
458
opts .SetLet (val .Document ())
459
+ case "rawData" :
460
+ err = xoptions .SetInternalDeleteOneOptions (opts , key , val .Boolean ())
461
+ if err != nil {
462
+ return nil , err
463
+ }
436
464
default :
437
465
return nil , fmt .Errorf ("unrecognized deleteOne option %q" , key )
438
466
}
@@ -487,6 +515,11 @@ func executeDeleteMany(ctx context.Context, operation *operation) (*operationRes
487
515
opts .SetHint (hint )
488
516
case "let" :
489
517
opts .SetLet (val .Document ())
518
+ case "rawData" :
519
+ err = xoptions .SetInternalDeleteManyOptions (opts , key , val .Boolean ())
520
+ if err != nil {
521
+ return nil , err
522
+ }
490
523
default :
491
524
return nil , fmt .Errorf ("unrecognized deleteMany option %q" , key )
492
525
}
@@ -545,6 +578,11 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
545
578
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
546
579
// this error.
547
580
return nil , fmt .Errorf ("the maxTimeMS collection option is not supported" )
581
+ case "rawData" :
582
+ err = xoptions .SetInternalDistinctOptions (opts , key , val .Boolean ())
583
+ if err != nil {
584
+ return nil , err
585
+ }
548
586
default :
549
587
return nil , fmt .Errorf ("unrecognized distinct option %q" , key )
550
588
}
@@ -593,6 +631,11 @@ func executeDropIndex(ctx context.Context, operation *operation) (*operationResu
593
631
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
594
632
// this error.
595
633
return nil , fmt .Errorf ("the maxTimeMS collection option is not supported" )
634
+ case "rawData" :
635
+ err = xoptions .SetInternalDropIndexesOptions (dropIndexOpts , key , val .Boolean ())
636
+ if err != nil {
637
+ return nil , err
638
+ }
596
639
default :
597
640
return nil , fmt .Errorf ("unrecognized dropIndex option %q" , key )
598
641
}
@@ -690,6 +733,11 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (*
690
733
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
691
734
// this error.
692
735
return nil , fmt .Errorf ("the maxTimeMS collection option is not supported" )
736
+ case "rawData" :
737
+ err = xoptions .SetInternalEstimatedDocumentCountOptions (opts , key , val .Boolean ())
738
+ if err != nil {
739
+ return nil , err
740
+ }
693
741
default :
694
742
return nil , fmt .Errorf ("unrecognized estimatedDocumentCount option %q" , key )
695
743
}
@@ -842,6 +890,11 @@ func executeFindOneAndDelete(ctx context.Context, operation *operation) (*operat
842
890
opts .SetSort (val .Document ())
843
891
case "let" :
844
892
opts .SetLet (val .Document ())
893
+ case "rawData" :
894
+ err = xoptions .SetInternalFindOneAndDeleteOptions (opts , key , val .Boolean ())
895
+ if err != nil {
896
+ return nil , err
897
+ }
845
898
default :
846
899
return nil , fmt .Errorf ("unrecognized findOneAndDelete option %q" , key )
847
900
}
@@ -924,6 +977,11 @@ func executeFindOneAndReplace(ctx context.Context, operation *operation) (*opera
924
977
opts .SetSort (val .Document ())
925
978
case "upsert" :
926
979
opts .SetUpsert (val .Boolean ())
980
+ case "rawData" :
981
+ err = xoptions .SetInternalFindOneAndReplaceOptions (opts , key , val .Boolean ())
982
+ if err != nil {
983
+ return nil , err
984
+ }
927
985
default :
928
986
return nil , fmt .Errorf ("unrecognized findOneAndReplace option %q" , key )
929
987
}
@@ -1016,6 +1074,11 @@ func executeFindOneAndUpdate(ctx context.Context, operation *operation) (*operat
1016
1074
}
1017
1075
case "upsert" :
1018
1076
opts .SetUpsert (val .Boolean ())
1077
+ case "rawData" :
1078
+ err = xoptions .SetInternalFindOneAndUpdateOptions (opts , key , val .Boolean ())
1079
+ if err != nil {
1080
+ return nil , err
1081
+ }
1019
1082
default :
1020
1083
return nil , fmt .Errorf ("unrecognized findOneAndUpdate option %q" , key )
1021
1084
}
@@ -1062,6 +1125,11 @@ func executeInsertMany(ctx context.Context, operation *operation) (*operationRes
1062
1125
documents = bsonutil .RawToInterfaces (bsonutil .RawArrayToDocuments (val .Array ())... )
1063
1126
case "ordered" :
1064
1127
opts .SetOrdered (val .Boolean ())
1128
+ case "rawData" :
1129
+ err = xoptions .SetInternalInsertManyOptions (opts , key , val .Boolean ())
1130
+ if err != nil {
1131
+ return nil , err
1132
+ }
1065
1133
default :
1066
1134
return nil , fmt .Errorf ("unrecognized insertMany option %q" , key )
1067
1135
}
@@ -1112,6 +1180,11 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
1112
1180
opts .SetBypassDocumentValidation (val .Boolean ())
1113
1181
case "comment" :
1114
1182
opts .SetComment (val )
1183
+ case "rawData" :
1184
+ err = xoptions .SetInternalInsertOneOptions (opts , key , val .Boolean ())
1185
+ if err != nil {
1186
+ return nil , err
1187
+ }
1115
1188
default :
1116
1189
return nil , fmt .Errorf ("unrecognized insertOne option %q" , key )
1117
1190
}
@@ -1156,6 +1229,11 @@ func executeListIndexes(ctx context.Context, operation *operation) (*operationRe
1156
1229
switch key {
1157
1230
case "batchSize" :
1158
1231
opts .SetBatchSize (val .Int32 ())
1232
+ case "rawData" :
1233
+ err = xoptions .SetInternalListIndexesOptions (opts , key , val .Boolean ())
1234
+ if err != nil {
1235
+ return nil , err
1236
+ }
1159
1237
default :
1160
1238
return nil , fmt .Errorf ("unrecognized listIndexes option: %q" , key )
1161
1239
}
@@ -1302,6 +1380,11 @@ func executeReplaceOne(ctx context.Context, operation *operation) (*operationRes
1302
1380
opts .SetUpsert (val .Boolean ())
1303
1381
case "let" :
1304
1382
opts .SetLet (val .Document ())
1383
+ case "rawData" :
1384
+ err = xoptions .SetInternalReplaceOptions (opts , key , val .Boolean ())
1385
+ if err != nil {
1386
+ return nil , err
1387
+ }
1305
1388
default :
1306
1389
return nil , fmt .Errorf ("unrecognized replaceOne option %q" , key )
1307
1390
}
@@ -1500,6 +1583,11 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult,
1500
1583
case "maxAwaitTimeMS" :
1501
1584
maxAwaitTimeMS := time .Duration (val .Int32 ()) * time .Millisecond
1502
1585
opts .SetMaxAwaitTime (maxAwaitTimeMS )
1586
+ case "rawData" :
1587
+ err = xoptions .SetInternalFindOptions (opts , key , val .Boolean ())
1588
+ if err != nil {
1589
+ return nil , err
1590
+ }
1503
1591
default :
1504
1592
return nil , fmt .Errorf ("unrecognized find option %q" , key )
1505
1593
}
0 commit comments