Skip to content

Commit 040f054

Browse files
committed
make rawDate internal
1 parent 2379c0c commit 040f054

File tree

7 files changed

+303
-136
lines changed

7 files changed

+303
-136
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
}

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-
}

mongo/options/findoptions.go

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ package options
88

99
import (
1010
"time"
11+
12+
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
1113
)
1214

1315
// FindOptions represents arguments that can be used to configure a Find
@@ -35,7 +37,10 @@ type FindOptions struct {
3537
Let interface{}
3638
Limit *int64
3739
NoCursorTimeout *bool
38-
RawData *bool
40+
41+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
42+
// release.
43+
CustomOptions optionsutil.Options
3944
}
4045

4146
// FindOptionsBuilder represents functional options that configure an Findopts.
@@ -269,18 +274,6 @@ func (f *FindOptionsBuilder) SetSort(sort interface{}) *FindOptionsBuilder {
269274
return f
270275
}
271276

272-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
273-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
274-
func (f *FindOptionsBuilder) SetRawData(rawData bool) *FindOptionsBuilder {
275-
f.Opts = append(f.Opts, func(opts *FindOptions) error {
276-
opts.RawData = &rawData
277-
278-
return nil
279-
})
280-
281-
return f
282-
}
283-
284277
// FindOneOptions represents arguments that can be used to configure a FindOne
285278
// operation.
286279
//
@@ -298,7 +291,10 @@ type FindOneOptions struct {
298291
ShowRecordID *bool
299292
Skip *int64
300293
Sort interface{}
301-
RawData *bool
294+
295+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
296+
// release.
297+
CustomOptions optionsutil.Options
302298
}
303299

304300
// FindOneOptionsBuilder represents functional options that configure an
@@ -450,17 +446,6 @@ func (f *FindOneOptionsBuilder) SetSort(sort interface{}) *FindOneOptionsBuilder
450446
return f
451447
}
452448

453-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
454-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
455-
func (f *FindOneOptionsBuilder) SetRawData(rawData bool) *FindOneOptionsBuilder {
456-
f.Opts = append(f.Opts, func(opts *FindOneOptions) error {
457-
opts.RawData = &rawData
458-
return nil
459-
})
460-
461-
return f
462-
}
463-
464449
// FindOneAndReplaceOptions represents arguments that can be used to configure a
465450
// FindOneAndReplace instance.
466451
//
@@ -475,7 +460,10 @@ type FindOneAndReplaceOptions struct {
475460
Upsert *bool
476461
Hint interface{}
477462
Let interface{}
478-
RawData *bool
463+
464+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
465+
// release.
466+
CustomOptions optionsutil.Options
479467
}
480468

481469
// FindOneAndReplaceOptionsBuilder contains options to perform a findAndModify
@@ -622,18 +610,6 @@ func (f *FindOneAndReplaceOptionsBuilder) SetLet(let interface{}) *FindOneAndRep
622610
return f
623611
}
624612

625-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
626-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
627-
func (f *FindOneAndReplaceOptionsBuilder) SetRawData(rawData bool) *FindOneAndReplaceOptionsBuilder {
628-
f.Opts = append(f.Opts, func(opts *FindOneAndReplaceOptions) error {
629-
opts.RawData = &rawData
630-
631-
return nil
632-
})
633-
634-
return f
635-
}
636-
637613
// FindOneAndUpdateOptions represents arguments that can be used to configure a
638614
// FindOneAndUpdate options.
639615
//
@@ -649,7 +625,10 @@ type FindOneAndUpdateOptions struct {
649625
Upsert *bool
650626
Hint interface{}
651627
Let interface{}
652-
RawData *bool
628+
629+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
630+
// release.
631+
CustomOptions optionsutil.Options
653632
}
654633

655634
// FindOneAndUpdateOptionsBuilder contains options to configure a
@@ -810,18 +789,6 @@ func (f *FindOneAndUpdateOptionsBuilder) SetLet(let interface{}) *FindOneAndUpda
810789
return f
811790
}
812791

813-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
814-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
815-
func (f *FindOneAndUpdateOptionsBuilder) SetRawData(rawData bool) *FindOneAndUpdateOptionsBuilder {
816-
f.Opts = append(f.Opts, func(opts *FindOneAndUpdateOptions) error {
817-
opts.RawData = &rawData
818-
819-
return nil
820-
})
821-
822-
return f
823-
}
824-
825792
// FindOneAndDeleteOptions represents arguments that can be used to configure a
826793
// FindOneAndDelete operation.
827794
//
@@ -833,7 +800,10 @@ type FindOneAndDeleteOptions struct {
833800
Sort interface{}
834801
Hint interface{}
835802
Let interface{}
836-
RawData *bool
803+
804+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
805+
// release.
806+
CustomOptions optionsutil.Options
837807
}
838808

839809
// FindOneAndDeleteOptionsBuilder contains options to configure delete
@@ -938,15 +908,3 @@ func (f *FindOneAndDeleteOptionsBuilder) SetLet(let interface{}) *FindOneAndDele
938908

939909
return f
940910
}
941-
942-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
943-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
944-
func (f *FindOneAndDeleteOptionsBuilder) SetRawData(rawData bool) *FindOneAndDeleteOptionsBuilder {
945-
f.Opts = append(f.Opts, func(opts *FindOneAndDeleteOptions) error {
946-
opts.RawData = &rawData
947-
948-
return nil
949-
})
950-
951-
return f
952-
}

0 commit comments

Comments
 (0)