Skip to content

Commit 2379c0c

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

File tree

9 files changed

+296
-131
lines changed

9 files changed

+296
-131
lines changed

internal/integration/unified/collection_operation_execution.go

Lines changed: 33 additions & 8 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 collection operations.
@@ -76,7 +77,10 @@ func executeAggregate(ctx context.Context, operation *operation) (*operationResu
7677
case "let":
7778
opts.SetLet(val.Document())
7879
case "rawData":
79-
opts.SetRawData(val.Boolean())
80+
err = xoptions.SetInternalAggregateOptions(opts, key, val.Boolean())
81+
if err != nil {
82+
return nil, err
83+
}
8084
default:
8185
return nil, fmt.Errorf("unrecognized aggregate option %q", key)
8286
}
@@ -207,7 +211,10 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio
207211
case "skip":
208212
opts.SetSkip(int64(val.Int32()))
209213
case "rawData":
210-
opts.SetRawData(val.Boolean())
214+
err = xoptions.SetInternalCountOptions(opts, key, val.Boolean())
215+
if err != nil {
216+
return nil, err
217+
}
211218
default:
212219
return nil, fmt.Errorf("unrecognized countDocuments option %q", key)
213220
}
@@ -440,7 +447,10 @@ func executeDeleteOne(ctx context.Context, operation *operation) (*operationResu
440447
case "let":
441448
opts.SetLet(val.Document())
442449
case "rawData":
443-
opts.SetRawData(val.Boolean())
450+
err = xoptions.SetInternalDeleteOneOptions(opts, key, val.Boolean())
451+
if err != nil {
452+
return nil, err
453+
}
444454
default:
445455
return nil, fmt.Errorf("unrecognized deleteOne option %q", key)
446456
}
@@ -496,7 +506,10 @@ func executeDeleteMany(ctx context.Context, operation *operation) (*operationRes
496506
case "let":
497507
opts.SetLet(val.Document())
498508
case "rawData":
499-
opts.SetRawData(val.Boolean())
509+
err = xoptions.SetInternalDeleteManyOptions(opts, key, val.Boolean())
510+
if err != nil {
511+
return nil, err
512+
}
500513
default:
501514
return nil, fmt.Errorf("unrecognized deleteMany option %q", key)
502515
}
@@ -556,7 +569,10 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
556569
// this error.
557570
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
558571
case "rawData":
559-
opts.SetRawData(val.Boolean())
572+
err = xoptions.SetInternalDistinctOptions(opts, key, val.Boolean())
573+
if err != nil {
574+
return nil, err
575+
}
560576
default:
561577
return nil, fmt.Errorf("unrecognized distinct option %q", key)
562578
}
@@ -703,7 +719,10 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (*
703719
// this error.
704720
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
705721
case "rawData":
706-
opts.SetRawData(val.Boolean())
722+
err = xoptions.SetInternalEstimatedDocumentCountOptions(opts, key, val.Boolean())
723+
if err != nil {
724+
return nil, err
725+
}
707726
default:
708727
return nil, fmt.Errorf("unrecognized estimatedDocumentCount option %q", key)
709728
}
@@ -1083,7 +1102,10 @@ func executeInsertMany(ctx context.Context, operation *operation) (*operationRes
10831102
case "ordered":
10841103
opts.SetOrdered(val.Boolean())
10851104
case "rawData":
1086-
opts.SetRawData(val.Boolean())
1105+
err = xoptions.SetInternalInsertManyOptions(opts, key, val.Boolean())
1106+
if err != nil {
1107+
return nil, err
1108+
}
10871109
default:
10881110
return nil, fmt.Errorf("unrecognized insertMany option %q", key)
10891111
}
@@ -1135,7 +1157,10 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
11351157
case "comment":
11361158
opts.SetComment(val)
11371159
case "rawData":
1138-
opts.SetRawData(val.Boolean())
1160+
err = xoptions.SetInternalInsertOneOptions(opts, key, val.Boolean())
1161+
if err != nil {
1162+
return nil, err
1163+
}
11391164
default:
11401165
return nil, fmt.Errorf("unrecognized insertOne option %q", key)
11411166
}

mongo/collection.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"go.mongodb.org/mongo-driver/v2/bson"
1818
"go.mongodb.org/mongo-driver/v2/internal/csfle"
1919
"go.mongodb.org/mongo-driver/v2/internal/mongoutil"
20+
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
2021
"go.mongodb.org/mongo-driver/v2/internal/serverselector"
2122
"go.mongodb.org/mongo-driver/v2/mongo/options"
2223
"go.mongodb.org/mongo-driver/v2/mongo/readconcern"
@@ -325,8 +326,10 @@ func (coll *Collection) insert(
325326
if args.Ordered != nil {
326327
op = op.Ordered(*args.Ordered)
327328
}
328-
if args.RawData != nil {
329-
op = op.RawData(*args.RawData)
329+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
330+
if rawData, ok := rawDataOpt.(bool); ok {
331+
op = op.RawData(rawData)
332+
}
330333
}
331334
retry := driver.RetryNone
332335
if coll.client.retryWrites {
@@ -379,8 +382,12 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{},
379382
if args.Comment != nil {
380383
imOpts.SetComment(args.Comment)
381384
}
382-
if args.RawData != nil {
383-
imOpts = imOpts.SetRawData(*args.RawData)
385+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
386+
imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error {
387+
optionsutil.WithValue(opts.CustomOptions, "rawData", rawDataOpt)
388+
389+
return nil
390+
})
384391
}
385392
res, err := coll.insert(ctx, []interface{}{document}, imOpts)
386393

@@ -541,8 +548,10 @@ func (coll *Collection) delete(
541548
}
542549
op = op.Let(let)
543550
}
544-
if args.RawData != nil {
545-
op = op.RawData(*args.RawData)
551+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
552+
if rawData, ok := rawDataOpt.(bool); ok {
553+
op = op.RawData(rawData)
554+
}
546555
}
547556

548557
// deleteMany cannot be retried
@@ -581,11 +590,11 @@ func (coll *Collection) DeleteOne(
581590
return nil, fmt.Errorf("failed to construct options from builder: %w", err)
582591
}
583592
deleteOptions := &options.DeleteManyOptions{
584-
Collation: args.Collation,
585-
Comment: args.Comment,
586-
Hint: args.Hint,
587-
Let: args.Let,
588-
RawData: args.RawData,
593+
Collation: args.Collation,
594+
Comment: args.Comment,
595+
Hint: args.Hint,
596+
Let: args.Let,
597+
CustomOptions: args.CustomOptions,
589598
}
590599

591600
return coll.delete(ctx, filter, true, rrOne, deleteOptions)
@@ -1052,8 +1061,10 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption
10521061
}
10531062
op.CustomOptions(customOptions)
10541063
}
1055-
if args.RawData != nil {
1056-
op = op.RawData(*args.RawData)
1064+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1065+
if rawData, ok := rawDataOpt.(bool); ok {
1066+
op = op.RawData(rawData)
1067+
}
10571068
}
10581069

10591070
retry := driver.RetryNone
@@ -1143,8 +1154,10 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
11431154
}
11441155
op.Hint(hintVal)
11451156
}
1146-
if args.RawData != nil {
1147-
op = op.RawData(*args.RawData)
1157+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1158+
if rawData, ok := rawDataOpt.(bool); ok {
1159+
op = op.RawData(rawData)
1160+
}
11481161
}
11491162
retry := driver.RetryNone
11501163
if coll.client.retryReads {
@@ -1227,8 +1240,10 @@ func (coll *Collection) EstimatedDocumentCount(
12271240
}
12281241
op = op.Comment(comment)
12291242
}
1230-
if args.RawData != nil {
1231-
op = op.RawData(*args.RawData)
1243+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1244+
if rawData, ok := rawDataOpt.(bool); ok {
1245+
op = op.RawData(rawData)
1246+
}
12321247
}
12331248

12341249
retry := driver.RetryNone
@@ -1319,8 +1334,10 @@ func (coll *Collection) Distinct(
13191334
}
13201335
op.Hint(hint)
13211336
}
1322-
if args.RawData != nil {
1323-
op = op.RawData(*args.RawData)
1337+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1338+
if rawData, ok := rawDataOpt.(bool); ok {
1339+
op = op.RawData(rawData)
1340+
}
13241341
}
13251342
retry := driver.RetryNone
13261343
if coll.client.retryReads {

mongo/options/aggregateoptions.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"go.mongodb.org/mongo-driver/v2/bson"
13+
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
1314
)
1415

1516
// AggregateOptions represents arguments that can be used to configure an
@@ -26,7 +27,10 @@ type AggregateOptions struct {
2627
Hint interface{}
2728
Let interface{}
2829
Custom bson.M
29-
RawData *bool
30+
31+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
32+
// release.
33+
CustomOptions optionsutil.Options
3034
}
3135

3236
// AggregateOptionsBuilder contains options to configure aggregate operations.
@@ -164,15 +168,3 @@ func (ao *AggregateOptionsBuilder) SetCustom(c bson.M) *AggregateOptionsBuilder
164168

165169
return ao
166170
}
167-
168-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
169-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
170-
func (ao *AggregateOptionsBuilder) SetRawData(rawData bool) *AggregateOptionsBuilder {
171-
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
172-
opts.RawData = &rawData
173-
174-
return nil
175-
})
176-
177-
return ao
178-
}

mongo/options/countoptions.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
// CountOptions represents arguments that can be used to configure a
1012
// CountDocuments operation.
1113
//
@@ -16,7 +18,10 @@ type CountOptions struct {
1618
Hint interface{}
1719
Limit *int64
1820
Skip *int64
19-
RawData *bool
21+
22+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
23+
// release.
24+
CustomOptions optionsutil.Options
2025
}
2126

2227
// CountOptionsBuilder contains options to configure count operations. Each
@@ -100,15 +105,3 @@ func (co *CountOptionsBuilder) SetSkip(i int64) *CountOptionsBuilder {
100105

101106
return co
102107
}
103-
104-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
105-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
106-
func (co *CountOptionsBuilder) SetRawData(rawData bool) *CountOptionsBuilder {
107-
co.Opts = append(co.Opts, func(opts *CountOptions) error {
108-
opts.RawData = &rawData
109-
110-
return nil
111-
})
112-
113-
return co
114-
}

mongo/options/deleteoptions.go

Lines changed: 10 additions & 26 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
// DeleteOneOptions represents arguments that can be used to configure DeleteOne
1012
// operations.
1113
//
@@ -15,7 +17,10 @@ type DeleteOneOptions struct {
1517
Comment interface{}
1618
Hint interface{}
1719
Let interface{}
18-
RawData *bool
20+
21+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
22+
// release.
23+
CustomOptions optionsutil.Options
1924
}
2025

2126
// DeleteOneOptionsBuilder contains options to configure DeleteOne operations. Each
@@ -94,18 +99,6 @@ func (do *DeleteOneOptionsBuilder) SetLet(let interface{}) *DeleteOneOptionsBuil
9499
return do
95100
}
96101

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 (do *DeleteOneOptionsBuilder) SetRawData(rawData bool) *DeleteOneOptionsBuilder {
100-
do.Opts = append(do.Opts, func(opts *DeleteOneOptions) error {
101-
opts.RawData = &rawData
102-
103-
return nil
104-
})
105-
106-
return do
107-
}
108-
109102
// DeleteManyOptions represents arguments that can be used to configure DeleteMany
110103
// operations.
111104
//
@@ -115,7 +108,10 @@ type DeleteManyOptions struct {
115108
Comment interface{}
116109
Hint interface{}
117110
Let interface{}
118-
RawData *bool
111+
112+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
113+
// release.
114+
CustomOptions optionsutil.Options
119115
}
120116

121117
// DeleteManyOptionsBuilder contains options to configure DeleteMany operations.
@@ -193,15 +189,3 @@ func (do *DeleteManyOptionsBuilder) SetLet(let interface{}) *DeleteManyOptionsBu
193189

194190
return do
195191
}
196-
197-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
198-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
199-
func (do *DeleteManyOptionsBuilder) SetRawData(rawData bool) *DeleteManyOptionsBuilder {
200-
do.Opts = append(do.Opts, func(opts *DeleteManyOptions) error {
201-
opts.RawData = &rawData
202-
203-
return nil
204-
})
205-
206-
return do
207-
}

mongo/options/distinctoptions.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
// DistinctOptions represents arguments that can be used to configure a Distinct
1012
// operation.
1113
//
@@ -14,7 +16,10 @@ type DistinctOptions struct {
1416
Collation *Collation
1517
Comment interface{}
1618
Hint interface{}
17-
RawData *bool
19+
20+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
21+
// release.
22+
CustomOptions optionsutil.Options
1823
}
1924

2025
// DistinctOptionsBuilder contains options to configure distinct operations. Each
@@ -78,15 +83,3 @@ func (do *DistinctOptionsBuilder) SetHint(hint interface{}) *DistinctOptionsBuil
7883

7984
return do
8085
}
81-
82-
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
83-
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
84-
func (do *DistinctOptionsBuilder) SetRawData(rawData bool) *DistinctOptionsBuilder {
85-
do.Opts = append(do.Opts, func(opts *DistinctOptions) error {
86-
opts.RawData = &rawData
87-
88-
return nil
89-
})
90-
91-
return do
92-
}

0 commit comments

Comments
 (0)