-
Notifications
You must be signed in to change notification settings - Fork 888
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
GODRIVER-3339 Separate Many
and One
for UpdateOptions
and DeleteOptions
.
#1819
base: master
Are you sure you want to change the base?
Conversation
API Change Report./v2/mongo/optionsincompatible changesDelete: removed compatible changesDeleteMany: added |
875fbb2
to
3b76520
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to update the migration guide to include sections about upgrading from options.Delete() and options.Update() to the new design.
func createUpdateArguments(args bson.Raw) (*updateArguments, error) { | ||
ua := &updateArguments{ | ||
opts: options.Update(), | ||
func createUpdateArguments[Options options.UpdateManyOptions | options.UpdateOneOptions]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not try to generalize this function. Instead, we should maintain createUpdateOneArguments
and createUpdateManyArguments
. Using the combination of reflection and generics here is difficult to read.
// A set of filters specifying to which array elements an update should apply. This option is only valid for MongoDB | ||
// versions >= 3.6. For previous server versions, the driver will return an error if this option is used. The | ||
// default value is nil, which means the update will apply to all array elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't expect users to interact with the ...Options
structs directly in most cases. We should move the struct field comments to the corresponding setter methods. Leave a comment on each struct field that references the corresponding setter method, like
See UpdateManyOptionsBuilder.SetArrayFilters for documentation.
This recommendation applies for the new DeleteManyOptions
also. Note that we will update the pattern for the rest of the options types with GODRIVER-3327.
if doc.multi { | ||
updateDoc = bsoncore.AppendBooleanElement(updateDoc, "multi", doc.multi) | ||
} | ||
if doc.sort != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc.sort
is currently never set. Will that be used in the follow-up GODRIVER-3285 PRs?
type updateOneArguments struct { | ||
filter bson.Raw | ||
update interface{} | ||
opts *options.UpdateOneOptionsBuilder | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid creating a new type here by separating filter
and update
from the options builder, allowing you to reuse updateArguments
in both functions.
E.g. updated function signatures:
func createUpdateOneArguments(args bson.Raw) (*updateArguments, *options.UpdateOneOptionsBuilder, error)
func createUpdateManyArguments(args bson.Raw) (*updateArguments, *options.UpdateManyOptionsBuilder, error)
GODRIVER-3339
Summary
Background & Motivation
For DRIVERS-2822,
sort
only applies toUpdateOne
. The server throws an error if asort
exists inUpdateMany
. Therefore, this PR proposes separating the options forUpdateOne
andUpdateMany
.Although there is no immediate requirement yet, the “DeleteOptions” struct is also considered to be divided for future changes as it is shared by both “DeleteOne” and “DeleteMany” now.