Skip to content

Commit 7154913

Browse files
committed
make rawDate internal
1 parent 2379c0c commit 7154913

File tree

8 files changed

+312
-138
lines changed

8 files changed

+312
-138
lines changed

internal/integration/unified/collection_operation_execution.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ func executeBulkWrite(ctx context.Context, operation *operation) (*operationResu
132132
case "let":
133133
opts.SetLet(val.Document())
134134
case "rawData":
135-
opts.SetRawData(val.Boolean())
135+
err = xoptions.SetInternalBulkWriteOptions(opts, key, val.Boolean())
136+
if err != nil {
137+
return nil, err
138+
}
136139
default:
137140
return nil, fmt.Errorf("unrecognized bulkWrite option %q", key)
138141
}
@@ -876,7 +879,10 @@ func executeFindOneAndDelete(ctx context.Context, operation *operation) (*operat
876879
case "let":
877880
opts.SetLet(val.Document())
878881
case "rawData":
879-
opts.SetRawData(val.Boolean())
882+
err = xoptions.SetInternalFindOneAndDeleteOptions(opts, key, val.Boolean())
883+
if err != nil {
884+
return nil, err
885+
}
880886
default:
881887
return nil, fmt.Errorf("unrecognized findOneAndDelete option %q", key)
882888
}
@@ -960,7 +966,10 @@ func executeFindOneAndReplace(ctx context.Context, operation *operation) (*opera
960966
case "upsert":
961967
opts.SetUpsert(val.Boolean())
962968
case "rawData":
963-
opts.SetRawData(val.Boolean())
969+
err = xoptions.SetInternalFindOneAndReplaceOptions(opts, key, val.Boolean())
970+
if err != nil {
971+
return nil, err
972+
}
964973
default:
965974
return nil, fmt.Errorf("unrecognized findOneAndReplace option %q", key)
966975
}
@@ -1054,7 +1063,10 @@ func executeFindOneAndUpdate(ctx context.Context, operation *operation) (*operat
10541063
case "upsert":
10551064
opts.SetUpsert(val.Boolean())
10561065
case "rawData":
1057-
opts.SetRawData(val.Boolean())
1066+
err = xoptions.SetInternalFindOneAndUpdateOptions(opts, key, val.Boolean())
1067+
if err != nil {
1068+
return nil, err
1069+
}
10581070
default:
10591071
return nil, fmt.Errorf("unrecognized findOneAndUpdate option %q", key)
10601072
}
@@ -1352,7 +1364,10 @@ func executeReplaceOne(ctx context.Context, operation *operation) (*operationRes
13521364
case "let":
13531365
opts.SetLet(val.Document())
13541366
case "rawData":
1355-
opts.SetRawData(val.Boolean())
1367+
err = xoptions.SetInternalReplaceOptions(opts, key, val.Boolean())
1368+
if err != nil {
1369+
return nil, err
1370+
}
13561371
default:
13571372
return nil, fmt.Errorf("unrecognized replaceOne option %q", key)
13581373
}
@@ -1552,7 +1567,10 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult,
15521567
maxAwaitTimeMS := time.Duration(val.Int32()) * time.Millisecond
15531568
opts.SetMaxAwaitTime(maxAwaitTimeMS)
15541569
case "rawData":
1555-
opts.SetRawData(val.Boolean())
1570+
err = xoptions.SetInternalFindOptions(opts, key, val.Boolean())
1571+
if err != nil {
1572+
return nil, err
1573+
}
15561574
default:
15571575
return nil, fmt.Errorf("unrecognized find option %q", key)
15581576
}

internal/integration/unified/crud_helpers.go

Lines changed: 9 additions & 2 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
@@ -68,7 +69,10 @@ func createUpdateManyArguments(args bson.Raw) (*updateArguments, *options.Update
6869
case "upsert":
6970
opts.SetUpsert(val.Boolean())
7071
case "rawData":
71-
opts.SetRawData(val.Boolean())
72+
err := xoptions.SetInternalUpdateManyOptions(opts, key, val.Boolean())
73+
if err != nil {
74+
return nil, nil, err
75+
}
7276
default:
7377
return nil, nil, fmt.Errorf("unrecognized update option %q", key)
7478
}
@@ -128,7 +132,10 @@ func createUpdateOneArguments(args bson.Raw) (*updateArguments, *options.UpdateO
128132
case "sort":
129133
opts.SetSort(val.Document())
130134
case "rawData":
131-
opts.SetRawData(val.Boolean())
135+
err := xoptions.SetInternalUpdateOneOptions(opts, key, val.Boolean())
136+
if err != nil {
137+
return nil, nil, err
138+
}
132139
default:
133140
return nil, nil, fmt.Errorf("unrecognized update option %q", key)
134141
}

mongo/collection.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ func (coll *Collection) BulkWrite(ctx context.Context, models []WriteModel,
245245
selector: selector,
246246
writeConcern: wc,
247247
let: args.Let,
248-
rawData: args.RawData,
248+
}
249+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
250+
if rawData, ok := rawDataOpt.(bool); ok {
251+
op.rawData = &rawData
252+
}
249253
}
250254

251255
err = op.execute(ctx)
@@ -701,8 +705,10 @@ func (coll *Collection) updateOrReplace(
701705
}
702706
op = op.Comment(comment)
703707
}
704-
if args.RawData != nil {
705-
op = op.RawData(*args.RawData)
708+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
709+
if rawData, ok := rawDataOpt.(bool); ok {
710+
op = op.RawData(rawData)
711+
}
706712
}
707713
retry := driver.RetryNone
708714
// retryable writes are only enabled updateOne/replaceOne operations
@@ -798,7 +804,7 @@ func (coll *Collection) UpdateOne(
798804
Hint: args.Hint,
799805
Upsert: args.Upsert,
800806
Let: args.Let,
801-
RawData: args.RawData,
807+
CustomOptions: args.CustomOptions,
802808
}
803809

804810
return coll.updateOrReplace(ctx, f, update, false, rrOne, true, args.Sort, updateOptions)
@@ -889,7 +895,7 @@ func (coll *Collection) ReplaceOne(
889895
Hint: args.Hint,
890896
Let: args.Let,
891897
Comment: args.Comment,
892-
RawData: args.RawData,
898+
CustomOptions: args.CustomOptions,
893899
}
894900

895901
return coll.updateOrReplace(ctx, f, r, false, rrOne, false, args.Sort, updateOptions)
@@ -1542,8 +1548,10 @@ func (coll *Collection) find(
15421548
}
15431549
op.Sort(sort)
15441550
}
1545-
if args.RawData != nil {
1546-
op = op.RawData(*args.RawData)
1551+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1552+
if rawData, ok := rawDataOpt.(bool); ok {
1553+
op = op.RawData(rawData)
1554+
}
15471555
}
15481556
retry := driver.RetryNone
15491557
if coll.client.retryReads {
@@ -1578,7 +1586,7 @@ func newFindArgsFromFindOneArgs(args *options.FindOneOptions) *options.FindOptio
15781586
v.ShowRecordID = args.ShowRecordID
15791587
v.Skip = args.Skip
15801588
v.Sort = args.Sort
1581-
v.RawData = args.RawData
1589+
v.CustomOptions = args.CustomOptions
15821590
}
15831591
return v
15841592
}
@@ -1741,8 +1749,10 @@ func (coll *Collection) FindOneAndDelete(
17411749
}
17421750
op = op.Let(let)
17431751
}
1744-
if args.RawData != nil {
1745-
op = op.RawData(*args.RawData)
1752+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1753+
if rawData, ok := rawDataOpt.(bool); ok {
1754+
op = op.RawData(rawData)
1755+
}
17461756
}
17471757

17481758
return coll.findAndModify(ctx, op)
@@ -1841,8 +1851,10 @@ func (coll *Collection) FindOneAndReplace(
18411851
}
18421852
op = op.Let(let)
18431853
}
1844-
if args.RawData != nil {
1845-
op = op.RawData(*args.RawData)
1854+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1855+
if rawData, ok := rawDataOpt.(bool); ok {
1856+
op = op.RawData(rawData)
1857+
}
18461858
}
18471859

18481860
return coll.findAndModify(ctx, op)
@@ -1953,8 +1965,10 @@ func (coll *Collection) FindOneAndUpdate(
19531965
}
19541966
op = op.Let(let)
19551967
}
1956-
if args.RawData != nil {
1957-
op = op.RawData(*args.RawData)
1968+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1969+
if rawData, ok := rawDataOpt.(bool); ok {
1970+
op = op.RawData(rawData)
1971+
}
19581972
}
19591973

19601974
return coll.findAndModify(ctx, op)

mongo/options/bulkwriteoptions.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package options
88

9+
import "go.mongodb.org/mongo-driver/v2/internal/optionsutil"
10+
911
// DefaultOrdered is the default value for the Ordered option in BulkWriteOptions.
1012
var DefaultOrdered = true
1113

@@ -18,7 +20,10 @@ type BulkWriteOptions struct {
1820
Comment interface{}
1921
Ordered *bool
2022
Let interface{}
21-
RawData *bool
23+
24+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
25+
// release.
26+
CustomOptions optionsutil.Options
2227
}
2328

2429
// BulkWriteOptionsBuilder contains options to configure bulk write operations.
@@ -93,15 +98,3 @@ func (b *BulkWriteOptionsBuilder) SetLet(let interface{}) *BulkWriteOptionsBuild
9398

9499
return b
95100
}
96-
97-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
98-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
99-
func (b *BulkWriteOptionsBuilder) SetRawData(rawData bool) *BulkWriteOptionsBuilder {
100-
b.Opts = append(b.Opts, func(opts *BulkWriteOptions) error {
101-
opts.RawData = &rawData
102-
103-
return nil
104-
})
105-
106-
return b
107-
}

0 commit comments

Comments
 (0)