diff --git a/internal/integration/unified/collection_operation_execution.go b/internal/integration/unified/collection_operation_execution.go index c3e7040256..be9afe0cd7 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) } @@ -125,6 +131,11 @@ func executeBulkWrite(ctx context.Context, operation *operation) (*operationResu } case "let": opts.SetLet(val.Document()) + case "rawData": + err = xoptions.SetInternalBulkWriteOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized bulkWrite option %q", key) } @@ -202,6 +213,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 +449,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 +508,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 +571,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 +721,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) } @@ -842,6 +878,11 @@ func executeFindOneAndDelete(ctx context.Context, operation *operation) (*operat opts.SetSort(val.Document()) case "let": opts.SetLet(val.Document()) + case "rawData": + err = xoptions.SetInternalFindOneAndDeleteOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized findOneAndDelete option %q", key) } @@ -924,6 +965,11 @@ func executeFindOneAndReplace(ctx context.Context, operation *operation) (*opera opts.SetSort(val.Document()) case "upsert": opts.SetUpsert(val.Boolean()) + case "rawData": + err = xoptions.SetInternalFindOneAndReplaceOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized findOneAndReplace option %q", key) } @@ -1016,6 +1062,11 @@ func executeFindOneAndUpdate(ctx context.Context, operation *operation) (*operat } case "upsert": opts.SetUpsert(val.Boolean()) + case "rawData": + err = xoptions.SetInternalFindOneAndUpdateOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized findOneAndUpdate option %q", key) } @@ -1062,6 +1113,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 +1168,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) } @@ -1302,6 +1363,11 @@ func executeReplaceOne(ctx context.Context, operation *operation) (*operationRes opts.SetUpsert(val.Boolean()) case "let": opts.SetLet(val.Document()) + case "rawData": + err = xoptions.SetInternalReplaceOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized replaceOne option %q", key) } @@ -1500,6 +1566,11 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult, case "maxAwaitTimeMS": maxAwaitTimeMS := time.Duration(val.Int32()) * time.Millisecond opts.SetMaxAwaitTime(maxAwaitTimeMS) + case "rawData": + err = xoptions.SetInternalFindOptions(opts, key, val.Boolean()) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("unrecognized find option %q", key) } diff --git a/internal/integration/unified/crud_helpers.go b/internal/integration/unified/crud_helpers.go index 34de29d683..98719224c4 100644 --- a/internal/integration/unified/crud_helpers.go +++ b/internal/integration/unified/crud_helpers.go @@ -12,6 +12,7 @@ import ( "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/internal/bsonutil" "go.mongodb.org/mongo-driver/v2/mongo/options" + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions" ) // newMissingArgumentError creates an error to convey that an argument that is required to run an operation is missing @@ -67,6 +68,11 @@ func createUpdateManyArguments(args bson.Raw) (*updateArguments, *options.Update } case "upsert": opts.SetUpsert(val.Boolean()) + case "rawData": + err := xoptions.SetInternalUpdateManyOptions(opts, key, val.Boolean()) + if err != nil { + return nil, nil, err + } default: return nil, nil, fmt.Errorf("unrecognized update option %q", key) } @@ -125,6 +131,11 @@ func createUpdateOneArguments(args bson.Raw) (*updateArguments, *options.UpdateO opts.SetUpsert(val.Boolean()) case "sort": opts.SetSort(val.Document()) + case "rawData": + err := xoptions.SetInternalUpdateOneOptions(opts, key, val.Boolean()) + if err != nil { + return nil, nil, err + } default: return nil, nil, fmt.Errorf("unrecognized update option %q", key) } diff --git a/mongo/bulk_write.go b/mongo/bulk_write.go index 415a90ae55..7a3181c6c4 100644 --- a/mongo/bulk_write.go +++ b/mongo/bulk_write.go @@ -39,6 +39,7 @@ type bulkWrite struct { writeConcern *writeconcern.WriteConcern result BulkWriteResult let interface{} + rawData *bool } func (bw *bulkWrite) execute(ctx context.Context) error { @@ -209,6 +210,10 @@ func (bw *bulkWrite) runInsert(ctx context.Context, batch bulkWriteBatch) (opera } op = op.Retry(retry) + if bw.rawData != nil { + op.RawData(*bw.rawData) + } + err := op.Execute(ctx) return op.Result(), err @@ -282,6 +287,10 @@ func (bw *bulkWrite) runDelete(ctx context.Context, batch bulkWriteBatch) (opera } op = op.Retry(retry) + if bw.rawData != nil { + op.RawData(*bw.rawData) + } + err := op.Execute(ctx) return op.Result(), err @@ -415,6 +424,10 @@ func (bw *bulkWrite) runUpdate(ctx context.Context, batch bulkWriteBatch) (opera } op = op.Retry(retry) + if bw.rawData != nil { + op.RawData(*bw.rawData) + } + err := op.Execute(ctx) return op.Result(), err diff --git a/mongo/collection.go b/mongo/collection.go index d7693c4245..6e842c11ec 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" @@ -245,6 +246,11 @@ func (coll *Collection) BulkWrite(ctx context.Context, models []WriteModel, writeConcern: wc, let: args.Let, } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op.rawData = &rawData + } + } err = op.execute(ctx) @@ -324,6 +330,11 @@ func (coll *Collection) insert( if args.Ordered != nil { op = op.Ordered(*args.Ordered) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "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 +386,13 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{}, if args.Comment != nil { imOpts.SetComment(args.Comment) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error { + optionsutil.WithValue(opts.CustomOptions, "rawData", rawDataOpt) + + return nil + }) + } res, err := coll.insert(ctx, []interface{}{document}, imOpts) rr, err := processWriteError(err) @@ -534,6 +552,11 @@ func (coll *Collection) delete( } op = op.Let(let) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } // deleteMany cannot be retried retryMode := driver.RetryNone @@ -571,10 +594,11 @@ func (coll *Collection) DeleteOne( return nil, fmt.Errorf("failed to construct options from builder: %w", err) } deleteOptions := &options.DeleteManyOptions{ - Collation: args.Collation, - Comment: args.Comment, - Hint: args.Hint, - Let: args.Let, + Collation: args.Collation, + Comment: args.Comment, + Hint: args.Hint, + Let: args.Let, + CustomOptions: args.CustomOptions, } return coll.delete(ctx, filter, true, rrOne, deleteOptions) @@ -681,6 +705,11 @@ func (coll *Collection) updateOrReplace( } op = op.Comment(comment) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone // retryable writes are only enabled updateOne/replaceOne operations if !multi && coll.client.retryWrites { @@ -775,6 +804,7 @@ func (coll *Collection) UpdateOne( Hint: args.Hint, Upsert: args.Upsert, Let: args.Let, + CustomOptions: args.CustomOptions, } return coll.updateOrReplace(ctx, f, update, false, rrOne, true, args.Sort, updateOptions) @@ -865,6 +895,7 @@ func (coll *Collection) ReplaceOne( Hint: args.Hint, Let: args.Let, Comment: args.Comment, + CustomOptions: args.CustomOptions, } return coll.updateOrReplace(ctx, f, r, false, rrOne, false, args.Sort, updateOptions) @@ -1036,6 +1067,11 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption } op.CustomOptions(customOptions) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if a.retryRead && !hasOutputStage { @@ -1124,6 +1160,11 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{}, } op.Hint(hintVal) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "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 +1246,11 @@ func (coll *Collection) EstimatedDocumentCount( } op = op.Comment(comment) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if coll.client.retryReads { @@ -1294,6 +1340,11 @@ func (coll *Collection) Distinct( } op.Hint(hint) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if coll.client.retryReads { retry = driver.RetryOncePerCommand @@ -1497,6 +1548,11 @@ func (coll *Collection) find( } op.Sort(sort) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } retry := driver.RetryNone if coll.client.retryReads { retry = driver.RetryOncePerCommand @@ -1530,6 +1586,7 @@ func newFindArgsFromFindOneArgs(args *options.FindOneOptions) *options.FindOptio v.ShowRecordID = args.ShowRecordID v.Skip = args.Skip v.Sort = args.Sort + v.CustomOptions = args.CustomOptions } return v } @@ -1692,6 +1749,11 @@ func (coll *Collection) FindOneAndDelete( } op = op.Let(let) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } return coll.findAndModify(ctx, op) } @@ -1789,6 +1851,11 @@ func (coll *Collection) FindOneAndReplace( } op = op.Let(let) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } return coll.findAndModify(ctx, op) } @@ -1898,6 +1965,11 @@ func (coll *Collection) FindOneAndUpdate( } op = op.Let(let) } + if rawDataOpt := optionsutil.Value(args.CustomOptions, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } + } return coll.findAndModify(ctx, op) } diff --git a/mongo/options/aggregateoptions.go b/mongo/options/aggregateoptions.go index cf419677dc..432358dfce 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. + CustomOptions optionsutil.Options } // AggregateOptionsBuilder contains options to configure aggregate operations. diff --git a/mongo/options/bulkwriteoptions.go b/mongo/options/bulkwriteoptions.go index 186e83a0c5..a3d6120b7a 100644 --- a/mongo/options/bulkwriteoptions.go +++ b/mongo/options/bulkwriteoptions.go @@ -6,6 +6,8 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // DefaultOrdered is the default value for the Ordered option in BulkWriteOptions. var DefaultOrdered = true @@ -18,6 +20,10 @@ type BulkWriteOptions struct { Comment interface{} Ordered *bool Let interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + CustomOptions optionsutil.Options } // BulkWriteOptionsBuilder contains options to configure bulk write operations. diff --git a/mongo/options/countoptions.go b/mongo/options/countoptions.go index 27df828b00..bc226fdc40 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. + CustomOptions optionsutil.Options } // CountOptionsBuilder contains options to configure count operations. Each diff --git a/mongo/options/deleteoptions.go b/mongo/options/deleteoptions.go index 1d045d9960..e19ecc5a92 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. + CustomOptions 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. + CustomOptions optionsutil.Options } // DeleteManyOptionsBuilder contains options to configure DeleteMany operations. diff --git a/mongo/options/distinctoptions.go b/mongo/options/distinctoptions.go index 3449ecee36..2de13e5774 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. + CustomOptions optionsutil.Options } // DistinctOptionsBuilder contains options to configure distinct operations. Each diff --git a/mongo/options/estimatedcountoptions.go b/mongo/options/estimatedcountoptions.go index 2bee45a8f6..ca1d9992cc 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. + CustomOptions optionsutil.Options } // EstimatedDocumentCountOptionsBuilder contains options to estimate document diff --git a/mongo/options/findoptions.go b/mongo/options/findoptions.go index ea627900ea..5e499718da 100644 --- a/mongo/options/findoptions.go +++ b/mongo/options/findoptions.go @@ -8,6 +8,8 @@ package options import ( "time" + + "go.mongodb.org/mongo-driver/v2/internal/optionsutil" ) // FindOptions represents arguments that can be used to configure a Find @@ -35,6 +37,10 @@ type FindOptions struct { Let interface{} Limit *int64 NoCursorTimeout *bool + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + CustomOptions optionsutil.Options } // FindOptionsBuilder represents functional options that configure an Findopts. @@ -285,6 +291,10 @@ type FindOneOptions struct { ShowRecordID *bool Skip *int64 Sort interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + CustomOptions optionsutil.Options } // FindOneOptionsBuilder represents functional options that configure an @@ -450,6 +460,10 @@ type FindOneAndReplaceOptions struct { Upsert *bool 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. + CustomOptions optionsutil.Options } // FindOneAndReplaceOptionsBuilder contains options to perform a findAndModify @@ -611,6 +625,10 @@ type FindOneAndUpdateOptions struct { Upsert *bool 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. + CustomOptions optionsutil.Options } // FindOneAndUpdateOptionsBuilder contains options to configure a @@ -782,6 +800,10 @@ type FindOneAndDeleteOptions struct { Sort 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. + CustomOptions optionsutil.Options } // FindOneAndDeleteOptionsBuilder contains options to configure delete diff --git a/mongo/options/insertoptions.go b/mongo/options/insertoptions.go index 61745600a9..90a5625189 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. + CustomOptions 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. + CustomOptions optionsutil.Options } // InsertManyOptionsBuilder contains options to configure insert operations. diff --git a/mongo/options/replaceoptions.go b/mongo/options/replaceoptions.go index 32caceff16..b8ade52ca0 100644 --- a/mongo/options/replaceoptions.go +++ b/mongo/options/replaceoptions.go @@ -6,6 +6,8 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // ReplaceOptions represents arguments that can be used to configure a ReplaceOne // operation. // @@ -18,6 +20,10 @@ type ReplaceOptions struct { Upsert *bool Let interface{} Sort interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + CustomOptions optionsutil.Options } // ReplaceOptionsBuilder contains options to configure replace operations. Each diff --git a/mongo/options/updateoptions.go b/mongo/options/updateoptions.go index f7b22e6f84..5b91e52c71 100644 --- a/mongo/options/updateoptions.go +++ b/mongo/options/updateoptions.go @@ -6,6 +6,8 @@ package options +import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" + // UpdateOneOptions represents arguments that can be used to configure UpdateOne // operations. // @@ -19,6 +21,10 @@ type UpdateOneOptions struct { Upsert *bool Let interface{} Sort interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + CustomOptions optionsutil.Options } // UpdateOneOptionsBuilder contains options to configure UpdateOne operations. @@ -164,6 +170,10 @@ type UpdateManyOptions struct { Hint interface{} Upsert *bool Let interface{} + + // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any + // release. + CustomOptions optionsutil.Options } // UpdateManyOptionsBuilder contains options to configure UpdateMany 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/find.go b/x/mongo/driver/operation/find.go index b607cb14d7..615e240850 100644 --- a/x/mongo/driver/operation/find.go +++ b/x/mongo/driver/operation/find.go @@ -61,6 +61,7 @@ type Find struct { result driver.CursorResponse serverAPI *driver.ServerAPIOptions timeout *time.Duration + rawData *bool logger *logger.Logger omitMaxTimeMS bool } @@ -191,6 +192,10 @@ func (f *Find) command(dst []byte, desc description.SelectedServer) ([]byte, err if f.tailable != nil { dst = bsoncore.AppendBooleanElement(dst, "tailable", *f.tailable) } + // Set rawData for 8.2+ servers. + if f.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *f.rawData) + } return dst, nil } @@ -565,6 +570,16 @@ func (f *Find) Authenticator(authenticator driver.Authenticator) *Find { return f } +// RawData sets the rawData to access timeseries data in the compressed format. +func (f *Find) RawData(rawData bool) *Find { + if f == nil { + f = new(Find) + } + + f.rawData = &rawData + return f +} + // OmitMaxTimeMS omits the automatically-calculated "maxTimeMS" from the // command. func (f *Find) OmitMaxTimeMS(omit bool) *Find { diff --git a/x/mongo/driver/operation/find_and_modify.go b/x/mongo/driver/operation/find_and_modify.go index 505c56b06c..2e524e78db 100644 --- a/x/mongo/driver/operation/find_and_modify.go +++ b/x/mongo/driver/operation/find_and_modify.go @@ -50,6 +50,7 @@ type FindAndModify struct { serverAPI *driver.ServerAPIOptions let bsoncore.Document timeout *time.Duration + rawData *bool result FindAndModifyResult } @@ -211,6 +212,10 @@ func (fam *FindAndModify) command(dst []byte, desc description.SelectedServer) ( if fam.let != nil { dst = bsoncore.AppendDocumentElement(dst, "let", fam.let) } + // Set rawData for 8.2+ servers. + if fam.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *fam.rawData) + } return dst, nil } @@ -476,3 +481,13 @@ func (fam *FindAndModify) Authenticator(authenticator driver.Authenticator) *Fin fam.authenticator = authenticator return fam } + +// RawData sets the rawData to access timeseries data in the compressed format. +func (fam *FindAndModify) RawData(rawData bool) *FindAndModify { + if fam == nil { + fam = new(FindAndModify) + } + + fam.rawData = &rawData + return fam +} 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/operation/update.go b/x/mongo/driver/operation/update.go index 722c06ef94..9b06deef33 100644 --- a/x/mongo/driver/operation/update.go +++ b/x/mongo/driver/operation/update.go @@ -46,6 +46,7 @@ type Update struct { serverAPI *driver.ServerAPIOptions let bsoncore.Document timeout *time.Duration + rawData *bool logger *logger.Logger } @@ -203,6 +204,10 @@ func (u *Update) command(dst []byte, desc description.SelectedServer) ([]byte, e if u.let != nil { dst = bsoncore.AppendDocumentElement(dst, "let", u.let) } + // Set rawData for 8.2+ servers. + if u.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { + dst = bsoncore.AppendBooleanElement(dst, "rawData", *u.rawData) + } return dst, nil } @@ -422,3 +427,13 @@ func (u *Update) Authenticator(authenticator driver.Authenticator) *Update { u.authenticator = authenticator return u } + +// RawData sets the rawData to access timeseries data in the compressed format. +func (u *Update) RawData(rawData bool) *Update { + if u == nil { + u = new(Update) + } + + u.rawData = &rawData + return u +} diff --git a/x/mongo/driver/xoptions/options.go b/x/mongo/driver/xoptions/options.go index 68e28e7cd8..6a6e3d957c 100644 --- a/x/mongo/driver/xoptions/options.go +++ b/x/mongo/driver/xoptions/options.go @@ -45,3 +45,394 @@ func SetInternalClientOptions(opts *options.ClientOptions, key string, option an } return nil } + +// SetInternalAggregateOptions sets internal options for AggregateOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalAggregateOptions(a *options.AggregateOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalBulkWriteOptions sets internal options for BulkWriteOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalBulkWriteOptions(a *options.BulkWriteOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.BulkWriteOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalCountOptions sets internal options for CountOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalCountOptions(a *options.CountOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalDeleteOneOptions sets internal options for DeleteOneOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalDeleteOneOptions(a *options.DeleteOneOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalDeleteManyOptions sets internal options for DeleteManyOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalDeleteManyOptions(a *options.DeleteManyOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalDistinctOptions sets internal options for DistinctOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalDistinctOptions(a *options.DistinctOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalEstimatedDocumentCountOptions sets internal options for EstimatedDocumentCountOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalEstimatedDocumentCountOptions(a *options.EstimatedDocumentCountOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalFindOptions sets internal options for FindOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalFindOptions(a *options.FindOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.FindOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalFindOneOptions sets internal options for FindOneOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalFindOneOptions(a *options.FindOneOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.FindOneOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalFindOneAndReplaceOptions sets internal options for FindOneAndReplaceOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalFindOneAndReplaceOptions(a *options.FindOneAndReplaceOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.FindOneAndReplaceOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalFindOneAndUpdateOptions sets internal options for FindOneAndUpdateOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalFindOneAndUpdateOptions(a *options.FindOneAndUpdateOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.FindOneAndUpdateOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalFindOneAndDeleteOptions sets internal options for FindOneAndDeleteOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalFindOneAndDeleteOptions(a *options.FindOneAndDeleteOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.FindOneAndDeleteOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalInsertManyOptions sets internal options for InsertManyOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalInsertManyOptions(a *options.InsertManyOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalInsertOneOptions sets internal options for InsertOneOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalInsertOneOptions(a *options.InsertOneOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalReplaceOptions sets internal options for ReplaceOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalReplaceOptions(a *options.ReplaceOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.ReplaceOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalUpdateManyOptions sets internal options for UpdateManyOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalUpdateManyOptions(a *options.UpdateManyOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.UpdateManyOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +} + +// SetInternalUpdateOneOptions sets internal options for UpdateOneOptions. +// +// Deprecated: This function is for internal use only. It may be changed or removed in any release. +func SetInternalUpdateOneOptions(a *options.UpdateOneOptionsBuilder, key string, option any) error { + typeErrFunc := func(t string) error { + return fmt.Errorf("unexpected type for %s: %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.UpdateOneOptions) error { + opts.CustomOptions = optionsutil.WithValue(opts.CustomOptions, key, b) + return nil + }) + default: + return fmt.Errorf("unsupported option: %s", key) + } + return nil +}