Skip to content
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

Return command error from findAndModify #2646

Merged
merged 17 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove js driver specific test
  • Loading branch information
chilagrow committed May 18, 2023
commit 4c3e9261409be7aac8696425706df13a44be6748
14 changes: 0 additions & 14 deletions integration/findandmodify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,6 @@ func TestFindAndModifyErrors(t *testing.T) {
},
altMessage: "BSON field 'findAndModify.upsert' is the wrong type 'string', expected type 'bool'",
},
"LowerCaseCommand": {
// go driver sends `findAndModify` in camel case, but
// js driver sends `findandmodify` in lower case.
findAndModify: "findandmodify",
command: bson.D{
{"update", bson.D{{"$set", bson.D{{"_id", "non-existent"}}}}},
},
err: &mongo.CommandError{
Code: 66,
Name: "ImmutableField",
Message: "Plan executor error during findAndModify :: caused by :: Performing an update on the path '_id' would modify the immutable field '_id'",
},
altMessage: "Performing an update on the path '_id' would modify the immutable field '_id'",
},
"SetUnsuitableValue": {
command: bson.D{
{"query", bson.D{{"_id", "array-documents-nested"}}},
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/common/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ func HasSupportedUpdateModifiers(command string, update *types.Document) (bool,
// newUpdateError returns CommandError for findAndModify command, WriteError for other commands.
func newUpdateError(code commonerrors.ErrorCode, msg, command string) error {
// Depending on the driver, the command may be camel case or lower case.
if strings.EqualFold(command, "findAndModify") {
if strings.ToLower(command) == "findandmodify" {
return commonerrors.NewCommandErrorMsgWithArgument(code, msg, command)
}

Expand Down
5 changes: 2 additions & 3 deletions internal/handlers/commonparams/extract_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func ExtractParams(doc *types.Document, command string, value any, l *zap.Logger

// If the key is the same as the command name, then it is a collection name.
// Depending on the driver, the key may be camel case or lower case for a collection name.
if strings.EqualFold(key, command) {
if strings.ToLower(key) == strings.ToLower(command) { //nolint:staticcheck // for clarity
lookup = "collection"
}

Expand Down Expand Up @@ -180,8 +180,7 @@ func lookupFieldTag(key string, value *reflect.Value) (*int, *tagOptions, error)

optionsList := strings.Split(tag, ",")

// Depending on the driver, the key may be camel case or lower case for a collection name.
if !strings.EqualFold(optionsList[0], key) {
if optionsList[0] != key {
continue
}

Expand Down