-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3582 Add custom options to client bulkWrite. #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ type clientBulkWrite struct { | |
selector description.ServerSelector | ||
writeConcern *writeconcern.WriteConcern | ||
rawData *bool | ||
bypassEmptyTsReplacement *bool | ||
commandCallback func([]byte, description.SelectedServer) ([]byte, error) | ||
|
||
result ClientBulkWriteResult | ||
} | ||
|
@@ -122,7 +124,8 @@ func (bw *clientBulkWrite) execute(ctx context.Context) error { | |
} | ||
|
||
func (bw *clientBulkWrite) newCommand() func([]byte, description.SelectedServer) ([]byte, error) { | ||
return func(dst []byte, desc description.SelectedServer) ([]byte, error) { | ||
return func(cmd []byte, desc description.SelectedServer) ([]byte, error) { | ||
var dst []byte | ||
dst = bsoncore.AppendInt32Element(dst, "bulkWrite", 1) | ||
|
||
dst = bsoncore.AppendBooleanElement(dst, "errorsOnly", bw.errorsOnly) | ||
|
@@ -148,7 +151,19 @@ func (bw *clientBulkWrite) newCommand() func([]byte, description.SelectedServer) | |
if bw.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { | ||
dst = bsoncore.AppendBooleanElement(dst, "rawData", *bw.rawData) | ||
} | ||
return dst, nil | ||
if bw.bypassEmptyTsReplacement != nil { | ||
dst = bsoncore.AppendBooleanElement(dst, "bypassEmptyTsReplacement", *bw.bypassEmptyTsReplacement) | ||
} | ||
if bw.commandCallback != nil { | ||
|
||
var err error | ||
dst, err = bw.commandCallback(dst, desc) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
cmd = append(cmd, dst...) | ||
return cmd, nil | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"go.mongodb.org/mongo-driver/v2/internal/optionsutil" | ||
"go.mongodb.org/mongo-driver/v2/mongo/options" | ||
"go.mongodb.org/mongo-driver/v2/x/mongo/driver" | ||
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/description" | ||
) | ||
|
||
// SetInternalClientOptions sets internal options for ClientOptions. | ||
|
@@ -101,6 +102,24 @@ func SetInternalClientBulkWriteOptions(a *options.ClientBulkWriteOptionsBuilder, | |
opts.Internal = optionsutil.WithValue(opts.Internal, key, b) | ||
return nil | ||
}) | ||
case "bypassEmptyTsReplacement": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we skip adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Despite being internal, I recommend retaining helper functions like |
||
b, ok := option.(bool) | ||
if !ok { | ||
return typeErrFunc("bool") | ||
} | ||
a.Opts = append(a.Opts, func(opts *options.ClientBulkWriteOptions) error { | ||
opts.Internal = optionsutil.WithValue(opts.Internal, key, b) | ||
return nil | ||
}) | ||
case "commandCallback": | ||
cb, ok := option.(func([]byte, description.SelectedServer) ([]byte, error)) | ||
if !ok { | ||
return typeErrFunc("func([]byte, description.SelectedServer) ([]byte, error)") | ||
} | ||
a.Opts = append(a.Opts, func(opts *options.ClientBulkWriteOptions) error { | ||
opts.Internal = optionsutil.WithValue(opts.Internal, key, cb) | ||
return nil | ||
}) | ||
default: | ||
return fmt.Errorf("unsupported option: %q", key) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.