Skip to content

Commit 4b6b175

Browse files
committed
make rawDate internal
1 parent 6724da3 commit 4b6b175

File tree

9 files changed

+272
-131
lines changed

9 files changed

+272
-131
lines changed

internal/integration/unified/collection_operation_execution.go

Lines changed: 9 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,7 @@ 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+
xoptions.SetInternalAggregateOptions(opts, key, val.Boolean())
8081
default:
8182
return nil, fmt.Errorf("unrecognized aggregate option %q", key)
8283
}
@@ -205,7 +206,7 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio
205206
case "skip":
206207
opts.SetSkip(int64(val.Int32()))
207208
case "rawData":
208-
opts.SetRawData(val.Boolean())
209+
xoptions.SetInternalCountOptions(opts, key, val.Boolean())
209210
default:
210211
return nil, fmt.Errorf("unrecognized countDocuments option %q", key)
211212
}
@@ -438,7 +439,7 @@ func executeDeleteOne(ctx context.Context, operation *operation) (*operationResu
438439
case "let":
439440
opts.SetLet(val.Document())
440441
case "rawData":
441-
opts.SetRawData(val.Boolean())
442+
xoptions.SetInternalDeleteOneOptions(opts, key, val.Boolean())
442443
default:
443444
return nil, fmt.Errorf("unrecognized deleteOne option %q", key)
444445
}
@@ -494,7 +495,7 @@ func executeDeleteMany(ctx context.Context, operation *operation) (*operationRes
494495
case "let":
495496
opts.SetLet(val.Document())
496497
case "rawData":
497-
opts.SetRawData(val.Boolean())
498+
xoptions.SetInternalDeleteManyOptions(opts, key, val.Boolean())
498499
default:
499500
return nil, fmt.Errorf("unrecognized deleteMany option %q", key)
500501
}
@@ -554,7 +555,7 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
554555
// this error.
555556
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
556557
case "rawData":
557-
opts.SetRawData(val.Boolean())
558+
xoptions.SetInternalDistinctOptions(opts, key, val.Boolean())
558559
default:
559560
return nil, fmt.Errorf("unrecognized distinct option %q", key)
560561
}
@@ -701,7 +702,7 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (*
701702
// this error.
702703
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
703704
case "rawData":
704-
opts.SetRawData(val.Boolean())
705+
xoptions.SetInternalEstimatedDocumentCountOptions(opts, key, val.Boolean())
705706
default:
706707
return nil, fmt.Errorf("unrecognized estimatedDocumentCount option %q", key)
707708
}
@@ -1075,7 +1076,7 @@ func executeInsertMany(ctx context.Context, operation *operation) (*operationRes
10751076
case "ordered":
10761077
opts.SetOrdered(val.Boolean())
10771078
case "rawData":
1078-
opts.SetRawData(val.Boolean())
1079+
xoptions.SetInternalInsertManyOptions(opts, key, val.Boolean())
10791080
default:
10801081
return nil, fmt.Errorf("unrecognized insertMany option %q", key)
10811082
}
@@ -1127,7 +1128,7 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
11271128
case "comment":
11281129
opts.SetComment(val)
11291130
case "rawData":
1130-
opts.SetRawData(val.Boolean())
1131+
xoptions.SetInternalInsertOneOptions(opts, key, val.Boolean())
11311132
default:
11321133
return nil, fmt.Errorf("unrecognized insertOne option %q", key)
11331134
}

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"
@@ -324,8 +325,10 @@ func (coll *Collection) insert(
324325
if args.Ordered != nil {
325326
op = op.Ordered(*args.Ordered)
326327
}
327-
if args.RawData != nil {
328-
op = op.RawData(*args.RawData)
328+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
329+
if rawData, ok := rawDataOpt.(bool); ok {
330+
op = op.RawData(rawData)
331+
}
329332
}
330333
retry := driver.RetryNone
331334
if coll.client.retryWrites {
@@ -378,8 +381,12 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{},
378381
if args.Comment != nil {
379382
imOpts.SetComment(args.Comment)
380383
}
381-
if args.RawData != nil {
382-
imOpts = imOpts.SetRawData(*args.RawData)
384+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
385+
imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error {
386+
optionsutil.WithValue(opts.CustomOptions, "rawData", rawDataOpt)
387+
388+
return nil
389+
})
383390
}
384391
res, err := coll.insert(ctx, []interface{}{document}, imOpts)
385392

@@ -540,8 +547,10 @@ func (coll *Collection) delete(
540547
}
541548
op = op.Let(let)
542549
}
543-
if args.RawData != nil {
544-
op = op.RawData(*args.RawData)
550+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
551+
if rawData, ok := rawDataOpt.(bool); ok {
552+
op = op.RawData(rawData)
553+
}
545554
}
546555

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

590599
return coll.delete(ctx, filter, true, rrOne, deleteOptions)
@@ -1046,8 +1055,10 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption
10461055
}
10471056
op.CustomOptions(customOptions)
10481057
}
1049-
if args.RawData != nil {
1050-
op = op.RawData(*args.RawData)
1058+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1059+
if rawData, ok := rawDataOpt.(bool); ok {
1060+
op = op.RawData(rawData)
1061+
}
10511062
}
10521063

10531064
retry := driver.RetryNone
@@ -1137,8 +1148,10 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
11371148
}
11381149
op.Hint(hintVal)
11391150
}
1140-
if args.RawData != nil {
1141-
op = op.RawData(*args.RawData)
1151+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1152+
if rawData, ok := rawDataOpt.(bool); ok {
1153+
op = op.RawData(rawData)
1154+
}
11421155
}
11431156
retry := driver.RetryNone
11441157
if coll.client.retryReads {
@@ -1221,8 +1234,10 @@ func (coll *Collection) EstimatedDocumentCount(
12211234
}
12221235
op = op.Comment(comment)
12231236
}
1224-
if args.RawData != nil {
1225-
op = op.RawData(*args.RawData)
1237+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1238+
if rawData, ok := rawDataOpt.(bool); ok {
1239+
op = op.RawData(rawData)
1240+
}
12261241
}
12271242

12281243
retry := driver.RetryNone
@@ -1313,8 +1328,10 @@ func (coll *Collection) Distinct(
13131328
}
13141329
op.Hint(hint)
13151330
}
1316-
if args.RawData != nil {
1317-
op = op.RawData(*args.RawData)
1331+
if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil {
1332+
if rawData, ok := rawDataOpt.(bool); ok {
1333+
op = op.RawData(rawData)
1334+
}
13181335
}
13191336
retry := driver.RetryNone
13201337
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)