diff --git a/internal/integration/unified/collection_operation_execution.go b/internal/integration/unified/collection_operation_execution.go index c3e7040256..e58a869eed 100644 --- a/internal/integration/unified/collection_operation_execution.go +++ b/internal/integration/unified/collection_operation_execution.go @@ -19,6 +19,7 @@ import ( "go.mongodb.org/mongo-driver/v2/mongo" "go.mongodb.org/mongo-driver/v2/mongo/options" "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore" + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions" ) // This file contains helpers to execute collection operations. @@ -75,6 +76,11 @@ func executeAggregate(ctx context.Context, operation *operation) (*operationResu pipeline = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...) case "let": opts.SetLet(val.Document()) + case "rawData": + err = xoptions.SetInternalAggregateOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized aggregate option %q", key) } @@ -202,6 +208,11 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio return nil, fmt.Errorf("the maxTimeMS collection option is not supported") case "skip": opts.SetSkip(int64(val.Int32())) + case "rawData": + err = xoptions.SetInternalCountOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized countDocuments option %q", key) } @@ -433,6 +444,11 @@ func executeDeleteOne(ctx context.Context, operation *operation) (*operationResu opts.SetHint(hint) case "let": opts.SetLet(val.Document()) + case "rawData": + err = xoptions.SetInternalDeleteOneOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized deleteOne option %q", key) } @@ -487,6 +503,11 @@ func executeDeleteMany(ctx context.Context, operation *operation) (*operationRes opts.SetHint(hint) case "let": opts.SetLet(val.Document()) + case "rawData": + err = xoptions.SetInternalDeleteManyOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized deleteMany option %q", key) } @@ -545,6 +566,11 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul // ensured an analogue exists, extend "skippedTestDescriptions" to avoid // this error. return nil, fmt.Errorf("the maxTimeMS collection option is not supported") + case "rawData": + err = xoptions.SetInternalDistinctOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized distinct option %q", key) } @@ -690,6 +716,11 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (* // ensured an analogue exists, extend "skippedTestDescriptions" to avoid // this error. return nil, fmt.Errorf("the maxTimeMS collection option is not supported") + case "rawData": + err = xoptions.SetInternalEstimatedDocumentCountOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized estimatedDocumentCount option %q", key) } @@ -1062,6 +1093,11 @@ func executeInsertMany(ctx context.Context, operation *operation) (*operationRes documents = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...) case "ordered": opts.SetOrdered(val.Boolean()) + case "rawData": + err = xoptions.SetInternalInsertManyOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized insertMany option %q", key) } @@ -1112,6 +1148,11 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu opts.SetBypassDocumentValidation(val.Boolean()) case "comment": opts.SetComment(val) + case "rawData": + err = xoptions.SetInternalInsertOneOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized insertOne option %q", key) } diff --git a/mongo/collection.go b/mongo/collection.go index d7693c4245..000b5b27b3 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -17,6 +17,7 @@ import ( "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/internal/csfle" "go.mongodb.org/mongo-driver/v2/internal/mongoutil" + "go.mongodb.org/mongo-driver/v2/internal/optionsutil" "go.mongodb.org/mongo-driver/v2/internal/serverselector" "go.mongodb.org/mongo-driver/v2/mongo/options" "go.mongodb.org/mongo-driver/v2/mongo/readconcern" @@ -324,6 +325,11 @@ func (coll *Collection) insert( if args.Ordered != nil { op = op.Ordered(*args.Ordered) } + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if coll.client.retryWrites { retry = driver.RetryOncePerCommand @@ -375,6 +381,13 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{}, if args.Comment != nil { imOpts.SetComment(args.Comment) } + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error { + optionsutil.WithValue(opts.Internal, "rawData", rawDataOpt) + + return nil + }) + } res, err := coll.insert(ctx, []interface{}{document}, imOpts) rr, err := processWriteError(err) @@ -534,6 +547,11 @@ func (coll *Collection) delete( } op = op.Let(let) } + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } // deleteMany cannot be retried retryMode := driver.RetryNone @@ -575,6 +593,7 @@ func (coll *Collection) DeleteOne( Comment: args.Comment, Hint: args.Hint, Let: args.Let, + Internal: args.Internal, } return coll.delete(ctx, filter, true, rrOne, deleteOptions) @@ -1036,6 +1055,11 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption } op.CustomOptions(customOptions) } + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if a.retryRead && !hasOutputStage { @@ -1124,6 +1148,11 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{}, } op.Hint(hintVal) } + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if coll.client.retryReads { retry = driver.RetryOncePerCommand @@ -1205,6 +1234,11 @@ func (coll *Collection) EstimatedDocumentCount( } op = op.Comment(comment) } + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if coll.client.retryReads { @@ -1294,6 +1328,11 @@ func (coll *Collection) Distinct( } op.Hint(hint) } + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if coll.client.retryReads { retry = driver.RetryOncePerCommand diff --git a/mongo/options/aggregateoptions.go b/mongo/options/aggregateoptions.go index cf419677dc..070e126583 100644 --- a/mongo/options/aggregateoptions.go +++ b/mongo/options/aggregateoptions.go @@ -10,6 +10,7 @@ import ( "time" "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/internal/optionsutil" ) // AggregateOptions represents arguments that can be used to configure an @@ -26,6 +27,10 @@ type AggregateOptions struct { Hint interface{} Let interface{} Custom bson.M + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // AggregateOptionsBuilder contains options to configure aggregate operations. diff --git a/mongo/options/countoptions.go b/mongo/options/countoptions.go index 27df828b00..3e689d9a54 100644 --- a/mongo/options/countoptions.go +++ b/mongo/options/countoptions.go @@ -6,6 +6,8 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // CountOptions represents arguments that can be used to configure a // CountDocuments operation. // @@ -16,6 +18,10 @@ type CountOptions struct { Hint interface{} Limit *int64 Skip *int64 + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // CountOptionsBuilder contains options to configure count operations. Each diff --git a/mongo/options/deleteoptions.go b/mongo/options/deleteoptions.go index 1d045d9960..27a77b4581 100644 --- a/mongo/options/deleteoptions.go +++ b/mongo/options/deleteoptions.go @@ -6,6 +6,8 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // DeleteOneOptions represents arguments that can be used to configure DeleteOne // operations. // @@ -15,6 +17,10 @@ type DeleteOneOptions struct { Comment interface{} Hint interface{} Let interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // DeleteOneOptionsBuilder contains options to configure DeleteOne operations. Each @@ -102,6 +108,10 @@ type DeleteManyOptions struct { Comment interface{} Hint interface{} Let interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // DeleteManyOptionsBuilder contains options to configure DeleteMany operations. diff --git a/mongo/options/distinctoptions.go b/mongo/options/distinctoptions.go index 3449ecee36..346432c07a 100644 --- a/mongo/options/distinctoptions.go +++ b/mongo/options/distinctoptions.go @@ -6,6 +6,8 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // DistinctOptions represents arguments that can be used to configure a Distinct // operation. // @@ -14,6 +16,10 @@ type DistinctOptions struct { Collation *Collation Comment interface{} Hint interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // DistinctOptionsBuilder contains options to configure distinct operations. Each diff --git a/mongo/options/estimatedcountoptions.go b/mongo/options/estimatedcountoptions.go index 2bee45a8f6..ccddd98c59 100644 --- a/mongo/options/estimatedcountoptions.go +++ b/mongo/options/estimatedcountoptions.go @@ -6,12 +6,18 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // EstimatedDocumentCountOptions represents arguments that can be used to configure // an EstimatedDocumentCount operation. // // See corresponding setter methods for documentation. type EstimatedDocumentCountOptions struct { Comment interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // EstimatedDocumentCountOptionsBuilder contains options to estimate document diff --git a/mongo/options/insertoptions.go b/mongo/options/insertoptions.go index 61745600a9..36f18a987d 100644 --- a/mongo/options/insertoptions.go +++ b/mongo/options/insertoptions.go @@ -6,6 +6,8 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // InsertOneOptions represents arguments that can be used to configure an InsertOne // operation. // @@ -13,6 +15,10 @@ package options type InsertOneOptions struct { BypassDocumentValidation *bool Comment interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // InsertOneOptionsBuilder represents functional options that configure an @@ -61,6 +67,10 @@ type InsertManyOptions struct { BypassDocumentValidation *bool Comment interface{} Ordered *bool + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + Internal optionsutil.Options } // InsertManyOptionsBuilder contains options to configure insert operations. diff --git a/x/mongo/driver/operation/aggregate.go b/x/mongo/driver/operation/aggregate.go index a0cd5bd25e..380789ab04 100644 --- a/x/mongo/driver/operation/aggregate.go +++ b/x/mongo/driver/operation/aggregate.go @@ -50,6 +50,7 @@ type Aggregate struct { customOptions map[string]bsoncore.Value timeout *time.Duration omitMaxTimeMS bool + rawData *bool result driver.CursorResponse } @@ -159,6 +160,10 @@ func (a *Aggregate) command(dst []byte, desc description.SelectedServer) ([]byte if a.let != nil { dst = bsoncore.AppendDocumentElement(dst, "let", a.let) } + // Set rawData for 8.2+ servers. + if a.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *a.rawData) + } for optionName, optionValue := range a.customOptions { dst = bsoncore.AppendValueElement(dst, optionName, optionValue) } @@ -431,3 +436,13 @@ func (a *Aggregate) OmitMaxTimeMS(omit bool) *Aggregate { a.omitMaxTimeMS = omit return a } + +// RawData sets the rawData to access timeseries data in the compressed format. +func (a *Aggregate) RawData(rawData bool) *Aggregate { + if a == nil { + a = new(Aggregate) + } + + a.rawData = &rawData + return a +} diff --git a/x/mongo/driver/operation/count.go b/x/mongo/driver/operation/count.go index 5ecaa3a936..d056702aab 100644 --- a/x/mongo/driver/operation/count.go +++ b/x/mongo/driver/operation/count.go @@ -41,6 +41,7 @@ type Count struct { result CountResult serverAPI *driver.ServerAPIOptions timeout *time.Duration + rawData *bool } // CountResult represents a count result returned by the server. @@ -139,7 +140,7 @@ func (c *Count) Execute(ctx context.Context) error { return err } -func (c *Count) command(dst []byte, _ description.SelectedServer) ([]byte, error) { +func (c *Count) command(dst []byte, desc description.SelectedServer) ([]byte, error) { dst = bsoncore.AppendStringElement(dst, "count", c.collection) if c.query != nil { dst = bsoncore.AppendDocumentElement(dst, "query", c.query) @@ -147,6 +148,10 @@ func (c *Count) command(dst []byte, _ description.SelectedServer) ([]byte, error if c.comment.Type != bsoncore.Type(0) { dst = bsoncore.AppendValueElement(dst, "comment", c.comment) } + // Set rawData for 8.2+ servers. + if c.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *c.rawData) + } return dst, nil } @@ -310,3 +315,13 @@ func (c *Count) Authenticator(authenticator driver.Authenticator) *Count { c.authenticator = authenticator return c } + +// RawData sets the rawData to access timeseries data in the compressed format. +func (c *Count) RawData(rawData bool) *Count { + if c == nil { + c = new(Count) + } + + c.rawData = &rawData + return c +} diff --git a/x/mongo/driver/operation/delete.go b/x/mongo/driver/operation/delete.go index e6f47042a8..e4510fb8fa 100644 --- a/x/mongo/driver/operation/delete.go +++ b/x/mongo/driver/operation/delete.go @@ -43,6 +43,7 @@ type Delete struct { serverAPI *driver.ServerAPIOptions let bsoncore.Document timeout *time.Duration + rawData *bool logger *logger.Logger } @@ -139,6 +140,10 @@ func (d *Delete) command(dst []byte, desc description.SelectedServer) ([]byte, e if d.let != nil { dst = bsoncore.AppendDocumentElement(dst, "let", d.let) } + // Set rawData for 8.2+ servers. + if d.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *d.rawData) + } return dst, nil } @@ -337,3 +342,13 @@ func (d *Delete) Authenticator(authenticator driver.Authenticator) *Delete { d.authenticator = authenticator return d } + +// RawData sets the rawData to access timeseries data in the compressed format. +func (d *Delete) RawData(rawData bool) *Delete { + if d == nil { + d = new(Delete) + } + + d.rawData = &rawData + return d +} diff --git a/x/mongo/driver/operation/distinct.go b/x/mongo/driver/operation/distinct.go index 89d412def3..ef235e2475 100644 --- a/x/mongo/driver/operation/distinct.go +++ b/x/mongo/driver/operation/distinct.go @@ -43,6 +43,7 @@ type Distinct struct { result DistinctResult serverAPI *driver.ServerAPIOptions timeout *time.Duration + rawData *bool } // DistinctResult represents a distinct result returned by the server. @@ -130,6 +131,10 @@ func (d *Distinct) command(dst []byte, desc description.SelectedServer) ([]byte, if d.query != nil { dst = bsoncore.AppendDocumentElement(dst, "query", d.query) } + // Set rawData for 8.2+ servers. + if d.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *d.rawData) + } return dst, nil } @@ -323,3 +328,13 @@ func (d *Distinct) Authenticator(authenticator driver.Authenticator) *Distinct { d.authenticator = authenticator return d } + +// RawData sets the rawData to access timeseries data in the compressed format. +func (d *Distinct) RawData(rawData bool) *Distinct { + if d == nil { + d = new(Distinct) + } + + d.rawData = &rawData + return d +} diff --git a/x/mongo/driver/operation/insert.go b/x/mongo/driver/operation/insert.go index b48e2c85f3..57d461ae3b 100644 --- a/x/mongo/driver/operation/insert.go +++ b/x/mongo/driver/operation/insert.go @@ -42,6 +42,7 @@ type Insert struct { result InsertResult serverAPI *driver.ServerAPIOptions timeout *time.Duration + rawData *bool logger *logger.Logger } @@ -132,6 +133,10 @@ func (i *Insert) command(dst []byte, desc description.SelectedServer) ([]byte, e if i.ordered != nil { dst = bsoncore.AppendBooleanElement(dst, "ordered", *i.ordered) } + // Set rawData for 8.2+ servers. + if i.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *i.rawData) + } return dst, nil } @@ -318,3 +323,13 @@ func (i *Insert) Authenticator(authenticator driver.Authenticator) *Insert { i.authenticator = authenticator return i } + +// RawData sets the rawData to access timeseries data in the compressed format. +func (i *Insert) RawData(rawData bool) *Insert { + if i == nil { + i = new(Insert) + } + + i.rawData = &rawData + return i +} diff --git a/x/mongo/driver/xoptions/options.go b/x/mongo/driver/xoptions/options.go index 68e28e7cd8..97c47e233f 100644 --- a/x/mongo/driver/xoptions/options.go +++ b/x/mongo/driver/xoptions/options.go @@ -15,11 +15,9 @@ import ( ) // SetInternalClientOptions sets internal options for ClientOptions. -// -// Deprecated: This function is for internal use only. It may be changed or removed in any release. func SetInternalClientOptions(opts *options.ClientOptions, key string, option any) error { typeErrFunc := func(t string) error { - return fmt.Errorf("unexpected type for %s: %T is not %s", key, option, t) + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) } switch key { case "crypt": @@ -45,3 +43,171 @@ func SetInternalClientOptions(opts *options.ClientOptions, key string, option an } return nil } + +// SetInternalAggregateOptions sets internal options for AggregateOptions. +func SetInternalAggregateOptions(a *options.AggregateOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.AggregateOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalCountOptions sets internal options for CountOptions. +func SetInternalCountOptions(a *options.CountOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.CountOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalDeleteOneOptions sets internal options for DeleteOneOptions. +func SetInternalDeleteOneOptions(a *options.DeleteOneOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.DeleteOneOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalDeleteManyOptions sets internal options for DeleteManyOptions. +func SetInternalDeleteManyOptions(a *options.DeleteManyOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.DeleteManyOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalDistinctOptions sets internal options for DistinctOptions. +func SetInternalDistinctOptions(a *options.DistinctOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.DistinctOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalEstimatedDocumentCountOptions sets internal options for EstimatedDocumentCountOptions. +func SetInternalEstimatedDocumentCountOptions(a *options.EstimatedDocumentCountOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.EstimatedDocumentCountOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalInsertManyOptions sets internal options for InsertManyOptions. +func SetInternalInsertManyOptions(a *options.InsertManyOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.InsertManyOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalInsertOneOptions sets internal options for InsertOneOptions. +func SetInternalInsertOneOptions(a *options.InsertOneOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %q: %T is not %s", key, option, t) + } + switch key { + case "rawData": + b, ok := option.(bool) + if !ok { + return typeErrFunc("bool") + } + a.Opts = append(a.Opts, func(opts *options.InsertOneOptions) error { + opts.Internal = optionsutil.WithValue(opts.Internal, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} diff --git a/x/mongo/driver/xoptions/options_test.go b/x/mongo/driver/xoptions/options_test.go index 284fe914a1..e56de6bdcc 100644 --- a/x/mongo/driver/xoptions/options_test.go +++ b/x/mongo/driver/xoptions/options_test.go @@ -58,7 +58,7 @@ func TestSetInternalClientOptions(t *testing.T) { opts := options.Client() err := SetInternalClientOptions(opts, "crypt", &drivertest.MockDeployment{}) - require.EqualError(t, err, "unexpected type for crypt: *drivertest.MockDeployment is not driver.Crypt") + require.EqualError(t, err, "unexpected type for \"crypt\": *drivertest.MockDeployment is not driver.Crypt") }) t.Run("set deployment", func(t *testing.T) { @@ -76,7 +76,7 @@ func TestSetInternalClientOptions(t *testing.T) { opts := options.Client() err := SetInternalClientOptions(opts, "deployment", driver.NewCrypt(&driver.CryptOptions{})) - require.EqualError(t, err, "unexpected type for deployment: *driver.crypt is not driver.Deployment") + require.EqualError(t, err, "unexpected type for \"deployment\": *driver.crypt is not driver.Deployment") }) t.Run("set unsupported option", func(t *testing.T) {