Skip to content

Commit 34bf3d8

Browse files
authored
GODRIVER-3522 Add support for the rawData option for time-series bucket access. (#2159)
1 parent f0469d0 commit 34bf3d8

36 files changed

+1002
-16
lines changed

internal/integration/unified/client_operation_execution.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"go.mongodb.org/mongo-driver/v2/mongo"
2020
"go.mongodb.org/mongo-driver/v2/mongo/options"
2121
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
22+
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions"
2223
)
2324

2425
// This file contains helpers to execute client operations.
@@ -235,6 +236,11 @@ func executeClientBulkWrite(ctx context.Context, operation *operation) (*operati
235236
return nil, err
236237
}
237238
opts.SetWriteConcern(c)
239+
case "rawData":
240+
err = xoptions.SetInternalClientBulkWriteOptions(opts, key, val.Boolean())
241+
if err != nil {
242+
return nil, err
243+
}
238244
default:
239245
return nil, fmt.Errorf("unrecognized bulkWrite option %q", key)
240246
}

internal/integration/unified/collection_operation_execution.go

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"go.mongodb.org/mongo-driver/v2/mongo"
2020
"go.mongodb.org/mongo-driver/v2/mongo/options"
2121
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
22+
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions"
2223
)
2324

2425
// This file contains helpers to execute collection operations.
@@ -75,6 +76,11 @@ func executeAggregate(ctx context.Context, operation *operation) (*operationResu
7576
pipeline = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...)
7677
case "let":
7778
opts.SetLet(val.Document())
79+
case "rawData":
80+
err = xoptions.SetInternalAggregateOptions(opts, key, val.Boolean())
81+
if err != nil {
82+
return nil, err
83+
}
7884
default:
7985
return nil, fmt.Errorf("unrecognized aggregate option %q", key)
8086
}
@@ -125,6 +131,11 @@ func executeBulkWrite(ctx context.Context, operation *operation) (*operationResu
125131
}
126132
case "let":
127133
opts.SetLet(val.Document())
134+
case "rawData":
135+
err = xoptions.SetInternalBulkWriteOptions(opts, key, val.Boolean())
136+
if err != nil {
137+
return nil, err
138+
}
128139
default:
129140
return nil, fmt.Errorf("unrecognized bulkWrite option %q", key)
130141
}
@@ -202,6 +213,11 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio
202213
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
203214
case "skip":
204215
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+
}
205221
default:
206222
return nil, fmt.Errorf("unrecognized countDocuments option %q", key)
207223
}
@@ -225,6 +241,7 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
225241

226242
var keys bson.Raw
227243
indexOpts := options.Index()
244+
opts := options.CreateIndexes()
228245

229246
elems, err := operation.Arguments.Elements()
230247
if err != nil {
@@ -279,6 +296,11 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
279296
indexOpts.SetWeights(val.Document())
280297
case "wildcardProjection":
281298
indexOpts.SetWildcardProjection(val.Document())
299+
case "rawData":
300+
err = xoptions.SetInternalCreateIndexesOptions(opts, key, val.Boolean())
301+
if err != nil {
302+
return nil, err
303+
}
282304
default:
283305
return nil, fmt.Errorf("unrecognized createIndex option %q", key)
284306
}
@@ -291,7 +313,8 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
291313
Keys: keys,
292314
Options: indexOpts,
293315
}
294-
name, err := coll.Indexes().CreateOne(ctx, model)
316+
317+
name, err := coll.Indexes().CreateOne(ctx, model, opts)
295318
return newValueResult(bson.TypeString, bsoncore.AppendString(nil, name), err), nil
296319
}
297320

@@ -433,6 +456,11 @@ func executeDeleteOne(ctx context.Context, operation *operation) (*operationResu
433456
opts.SetHint(hint)
434457
case "let":
435458
opts.SetLet(val.Document())
459+
case "rawData":
460+
err = xoptions.SetInternalDeleteOneOptions(opts, key, val.Boolean())
461+
if err != nil {
462+
return nil, err
463+
}
436464
default:
437465
return nil, fmt.Errorf("unrecognized deleteOne option %q", key)
438466
}
@@ -487,6 +515,11 @@ func executeDeleteMany(ctx context.Context, operation *operation) (*operationRes
487515
opts.SetHint(hint)
488516
case "let":
489517
opts.SetLet(val.Document())
518+
case "rawData":
519+
err = xoptions.SetInternalDeleteManyOptions(opts, key, val.Boolean())
520+
if err != nil {
521+
return nil, err
522+
}
490523
default:
491524
return nil, fmt.Errorf("unrecognized deleteMany option %q", key)
492525
}
@@ -545,6 +578,11 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
545578
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
546579
// this error.
547580
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+
}
548586
default:
549587
return nil, fmt.Errorf("unrecognized distinct option %q", key)
550588
}
@@ -593,6 +631,11 @@ func executeDropIndex(ctx context.Context, operation *operation) (*operationResu
593631
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
594632
// this error.
595633
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+
}
596639
default:
597640
return nil, fmt.Errorf("unrecognized dropIndex option %q", key)
598641
}
@@ -690,6 +733,11 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (*
690733
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
691734
// this error.
692735
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+
}
693741
default:
694742
return nil, fmt.Errorf("unrecognized estimatedDocumentCount option %q", key)
695743
}
@@ -842,6 +890,11 @@ func executeFindOneAndDelete(ctx context.Context, operation *operation) (*operat
842890
opts.SetSort(val.Document())
843891
case "let":
844892
opts.SetLet(val.Document())
893+
case "rawData":
894+
err = xoptions.SetInternalFindOneAndDeleteOptions(opts, key, val.Boolean())
895+
if err != nil {
896+
return nil, err
897+
}
845898
default:
846899
return nil, fmt.Errorf("unrecognized findOneAndDelete option %q", key)
847900
}
@@ -924,6 +977,11 @@ func executeFindOneAndReplace(ctx context.Context, operation *operation) (*opera
924977
opts.SetSort(val.Document())
925978
case "upsert":
926979
opts.SetUpsert(val.Boolean())
980+
case "rawData":
981+
err = xoptions.SetInternalFindOneAndReplaceOptions(opts, key, val.Boolean())
982+
if err != nil {
983+
return nil, err
984+
}
927985
default:
928986
return nil, fmt.Errorf("unrecognized findOneAndReplace option %q", key)
929987
}
@@ -1016,6 +1074,11 @@ func executeFindOneAndUpdate(ctx context.Context, operation *operation) (*operat
10161074
}
10171075
case "upsert":
10181076
opts.SetUpsert(val.Boolean())
1077+
case "rawData":
1078+
err = xoptions.SetInternalFindOneAndUpdateOptions(opts, key, val.Boolean())
1079+
if err != nil {
1080+
return nil, err
1081+
}
10191082
default:
10201083
return nil, fmt.Errorf("unrecognized findOneAndUpdate option %q", key)
10211084
}
@@ -1062,6 +1125,11 @@ func executeInsertMany(ctx context.Context, operation *operation) (*operationRes
10621125
documents = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...)
10631126
case "ordered":
10641127
opts.SetOrdered(val.Boolean())
1128+
case "rawData":
1129+
err = xoptions.SetInternalInsertManyOptions(opts, key, val.Boolean())
1130+
if err != nil {
1131+
return nil, err
1132+
}
10651133
default:
10661134
return nil, fmt.Errorf("unrecognized insertMany option %q", key)
10671135
}
@@ -1112,6 +1180,11 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
11121180
opts.SetBypassDocumentValidation(val.Boolean())
11131181
case "comment":
11141182
opts.SetComment(val)
1183+
case "rawData":
1184+
err = xoptions.SetInternalInsertOneOptions(opts, key, val.Boolean())
1185+
if err != nil {
1186+
return nil, err
1187+
}
11151188
default:
11161189
return nil, fmt.Errorf("unrecognized insertOne option %q", key)
11171190
}
@@ -1156,6 +1229,11 @@ func executeListIndexes(ctx context.Context, operation *operation) (*operationRe
11561229
switch key {
11571230
case "batchSize":
11581231
opts.SetBatchSize(val.Int32())
1232+
case "rawData":
1233+
err = xoptions.SetInternalListIndexesOptions(opts, key, val.Boolean())
1234+
if err != nil {
1235+
return nil, err
1236+
}
11591237
default:
11601238
return nil, fmt.Errorf("unrecognized listIndexes option: %q", key)
11611239
}
@@ -1302,6 +1380,11 @@ func executeReplaceOne(ctx context.Context, operation *operation) (*operationRes
13021380
opts.SetUpsert(val.Boolean())
13031381
case "let":
13041382
opts.SetLet(val.Document())
1383+
case "rawData":
1384+
err = xoptions.SetInternalReplaceOptions(opts, key, val.Boolean())
1385+
if err != nil {
1386+
return nil, err
1387+
}
13051388
default:
13061389
return nil, fmt.Errorf("unrecognized replaceOne option %q", key)
13071390
}
@@ -1500,6 +1583,11 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult,
15001583
case "maxAwaitTimeMS":
15011584
maxAwaitTimeMS := time.Duration(val.Int32()) * time.Millisecond
15021585
opts.SetMaxAwaitTime(maxAwaitTimeMS)
1586+
case "rawData":
1587+
err = xoptions.SetInternalFindOptions(opts, key, val.Boolean())
1588+
if err != nil {
1589+
return nil, err
1590+
}
15031591
default:
15041592
return nil, fmt.Errorf("unrecognized find option %q", key)
15051593
}

internal/integration/unified/crud_helpers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go.mongodb.org/mongo-driver/v2/bson"
1313
"go.mongodb.org/mongo-driver/v2/internal/bsonutil"
1414
"go.mongodb.org/mongo-driver/v2/mongo/options"
15+
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions"
1516
)
1617

1718
// newMissingArgumentError creates an error to convey that an argument that is required to run an operation is missing
@@ -67,6 +68,11 @@ func createUpdateManyArguments(args bson.Raw) (*updateArguments, *options.Update
6768
}
6869
case "upsert":
6970
opts.SetUpsert(val.Boolean())
71+
case "rawData":
72+
err := xoptions.SetInternalUpdateManyOptions(opts, key, val.Boolean())
73+
if err != nil {
74+
return nil, nil, err
75+
}
7076
default:
7177
return nil, nil, fmt.Errorf("unrecognized update option %q", key)
7278
}
@@ -125,6 +131,11 @@ func createUpdateOneArguments(args bson.Raw) (*updateArguments, *options.UpdateO
125131
opts.SetUpsert(val.Boolean())
126132
case "sort":
127133
opts.SetSort(val.Document())
134+
case "rawData":
135+
err := xoptions.SetInternalUpdateOneOptions(opts, key, val.Boolean())
136+
if err != nil {
137+
return nil, nil, err
138+
}
128139
default:
129140
return nil, nil, fmt.Errorf("unrecognized update option %q", key)
130141
}
@@ -162,6 +173,11 @@ func createListCollectionsArguments(args bson.Raw) (*listCollectionsArguments, e
162173
lca.filter = val.Document()
163174
case "nameOnly":
164175
lca.opts.SetNameOnly(val.Boolean())
176+
case "rawData":
177+
err := xoptions.SetInternalListCollectionsOptions(lca.opts, key, val.Boolean())
178+
if err != nil {
179+
return nil, err
180+
}
165181
default:
166182
return nil, fmt.Errorf("unrecognized listCollections option %q", key)
167183
}

mongo/bulk_write.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type bulkWrite struct {
3939
writeConcern *writeconcern.WriteConcern
4040
result BulkWriteResult
4141
let interface{}
42+
rawData *bool
4243
}
4344

4445
func (bw *bulkWrite) execute(ctx context.Context) error {
@@ -209,6 +210,10 @@ func (bw *bulkWrite) runInsert(ctx context.Context, batch bulkWriteBatch) (opera
209210
}
210211
op = op.Retry(retry)
211212

213+
if bw.rawData != nil {
214+
op.RawData(*bw.rawData)
215+
}
216+
212217
err := op.Execute(ctx)
213218

214219
return op.Result(), err
@@ -282,6 +287,10 @@ func (bw *bulkWrite) runDelete(ctx context.Context, batch bulkWriteBatch) (opera
282287
}
283288
op = op.Retry(retry)
284289

290+
if bw.rawData != nil {
291+
op.RawData(*bw.rawData)
292+
}
293+
285294
err := op.Execute(ctx)
286295

287296
return op.Result(), err
@@ -415,6 +424,10 @@ func (bw *bulkWrite) runUpdate(ctx context.Context, batch bulkWriteBatch) (opera
415424
}
416425
op = op.Retry(retry)
417426

427+
if bw.rawData != nil {
428+
op.RawData(*bw.rawData)
429+
}
430+
418431
err := op.Execute(ctx)
419432

420433
return op.Result(), err

mongo/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"go.mongodb.org/mongo-driver/v2/internal/httputil"
1919
"go.mongodb.org/mongo-driver/v2/internal/logger"
2020
"go.mongodb.org/mongo-driver/v2/internal/mongoutil"
21+
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
2122
"go.mongodb.org/mongo-driver/v2/internal/ptrutil"
2223
"go.mongodb.org/mongo-driver/v2/internal/serverselector"
2324
"go.mongodb.org/mongo-driver/v2/internal/uuid"
@@ -957,6 +958,11 @@ func (c *Client) BulkWrite(ctx context.Context, writes []ClientBulkWrite,
957958
selector: selector,
958959
writeConcern: wc,
959960
}
961+
if rawDataOpt := optionsutil.Value(bwo.Internal, "rawData"); rawDataOpt != nil {
962+
if rawData, ok := rawDataOpt.(bool); ok {
963+
op.rawData = &rawData
964+
}
965+
}
960966
if bwo.VerboseResults == nil || !(*bwo.VerboseResults) {
961967
op.errorsOnly = true
962968
} else if !acknowledged {

mongo/client_bulk_write.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type clientBulkWrite struct {
4444
client *Client
4545
selector description.ServerSelector
4646
writeConcern *writeconcern.WriteConcern
47+
rawData *bool
4748

4849
result ClientBulkWriteResult
4950
}
@@ -143,6 +144,10 @@ func (bw *clientBulkWrite) newCommand() func([]byte, description.SelectedServer)
143144
}
144145
dst = bsoncore.AppendDocumentElement(dst, "let", let)
145146
}
147+
// Set rawData for 8.2+ servers.
148+
if bw.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
149+
dst = bsoncore.AppendBooleanElement(dst, "rawData", *bw.rawData)
150+
}
146151
return dst, nil
147152
}
148153
}

0 commit comments

Comments
 (0)