Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions internal/integration/unified/collection_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,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)
}
Expand Down Expand Up @@ -873,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)
}
Expand Down Expand Up @@ -955,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)
}
Expand Down Expand Up @@ -1047,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)
}
Expand Down Expand Up @@ -1343,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)
}
Expand Down Expand Up @@ -1541,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)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/integration/unified/crud_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
13 changes: 13 additions & 0 deletions mongo/bulk_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type bulkWrite struct {
writeConcern *writeconcern.WriteConcern
result BulkWriteResult
let interface{}
rawData *bool
}

func (bw *bulkWrite) execute(ctx context.Context) error {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ func (coll *Collection) BulkWrite(ctx context.Context, models []WriteModel,
writeConcern: wc,
let: args.Let,
}
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op.rawData = &rawData
}
}

err = op.execute(ctx)

Expand Down Expand Up @@ -700,6 +705,11 @@ func (coll *Collection) updateOrReplace(
}
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
// retryable writes are only enabled updateOne/replaceOne operations
if !multi && coll.client.retryWrites {
Expand Down Expand Up @@ -794,6 +804,7 @@ func (coll *Collection) UpdateOne(
Hint: args.Hint,
Upsert: args.Upsert,
Let: args.Let,
Internal: args.Internal,
}

return coll.updateOrReplace(ctx, f, update, false, rrOne, true, args.Sort, updateOptions)
Expand Down Expand Up @@ -884,6 +895,7 @@ func (coll *Collection) ReplaceOne(
Hint: args.Hint,
Let: args.Let,
Comment: args.Comment,
Internal: args.Internal,
}

return coll.updateOrReplace(ctx, f, r, false, rrOne, false, args.Sort, updateOptions)
Expand Down Expand Up @@ -1536,6 +1548,11 @@ func (coll *Collection) find(
}
op.Sort(sort)
}
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
Expand Down Expand Up @@ -1569,6 +1586,7 @@ func newFindArgsFromFindOneArgs(args *options.FindOneOptions) *options.FindOptio
v.ShowRecordID = args.ShowRecordID
v.Skip = args.Skip
v.Sort = args.Sort
v.Internal = args.Internal
}
return v
}
Expand Down Expand Up @@ -1731,6 +1749,11 @@ func (coll *Collection) FindOneAndDelete(
}
op = op.Let(let)
}
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op = op.RawData(rawData)
}
}

return coll.findAndModify(ctx, op)
}
Expand Down Expand Up @@ -1828,6 +1851,11 @@ func (coll *Collection) FindOneAndReplace(
}
op = op.Let(let)
}
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op = op.RawData(rawData)
}
}

return coll.findAndModify(ctx, op)
}
Expand Down Expand Up @@ -1937,6 +1965,11 @@ func (coll *Collection) FindOneAndUpdate(
}
op = op.Let(let)
}
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op = op.RawData(rawData)
}
}

return coll.findAndModify(ctx, op)
}
Expand Down
6 changes: 6 additions & 0 deletions mongo/options/bulkwriteoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Internal optionsutil.Options
}

// BulkWriteOptionsBuilder contains options to configure bulk write operations.
Expand Down
22 changes: 22 additions & 0 deletions mongo/options/findoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Internal optionsutil.Options
}

// FindOptionsBuilder represents functional options that configure an Findopts.
Expand Down Expand Up @@ -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.
Internal optionsutil.Options
}

// FindOneOptionsBuilder represents functional options that configure an
Expand Down Expand Up @@ -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.
Internal optionsutil.Options
}

// FindOneAndReplaceOptionsBuilder contains options to perform a findAndModify
Expand Down Expand Up @@ -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.
Internal optionsutil.Options
}

// FindOneAndUpdateOptionsBuilder contains options to configure a
Expand Down Expand Up @@ -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.
Internal optionsutil.Options
}

// FindOneAndDeleteOptionsBuilder contains options to configure delete
Expand Down
6 changes: 6 additions & 0 deletions mongo/options/replaceoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand All @@ -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.
Internal optionsutil.Options
}

// ReplaceOptionsBuilder contains options to configure replace operations. Each
Expand Down
10 changes: 10 additions & 0 deletions mongo/options/updateoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand All @@ -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.
Internal optionsutil.Options
}

// UpdateOneOptionsBuilder contains options to configure UpdateOne operations.
Expand Down Expand Up @@ -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.
Internal optionsutil.Options
}

// UpdateManyOptionsBuilder contains options to configure UpdateMany operations.
Expand Down
Loading
Loading