-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Cannot use context bind on a struct with "primitive.ObjectID" #1664
Comments
Up ! |
Hy @pierremarsotlyon1 and @norx85 If you have worked with a version of echo that does not have this issue could you also tell the version? |
Hi @iambenkay I downgrade echo version to v3.3.10-dev. I have this issue with echo version v4.1.17 |
@pierremarsotlyon1 I can't seem to recreate this issue using v4.1.17 here is a snippet https://repl.it/@iambenkay/Golang-Mongo-ID-bug If possible tweak this to recreate the issue you're facing so the community can help |
You can reproduce with this snippet : https://repl.it/@PierreMarsot/Golang-Mongo-ID-bug |
You need to add the type User struct {
ID primitive.ObjectID `param:"id,omitempty"`
} the |
With version 3, we don't need to do that My struct :
My url : I get my id param like this : It is outside of my struct Basically, i can put a param in my url and don't have it in my struct |
okay. well that was a breaking change between v3 and v4. The bind was improved to automatically bind the url params, the request body and the query params into the struct. Although there have been a few issues on the restrictive nature of using one bind call for all the data units in the request and a PR is in the works at #1681 to separate the bind functions for each of them. I think this feature is currently reserved for v5 |
@pierremarsotlyon1 if you want only to handle json POST, avoid c.Bind() and just decode body directly to struct type User struct {
Id primitive.ObjectID `json:"_id" bson:"_id,omitempty"`
}
item := new(User)
if err := json.NewDecoder(c.Request().Body).Decode(item); err != nil {
return err
} and get path variable with |
Sorry for delay |
Issue Description
It's impossible to bind the body of a request on a struct with primitive.ObjectID from the official mongodb mongo-driver
Expected behaviour
The string value of the id correctly mapped to primitive.ObjectID and no errors, as it was on older releases (this problem happens to me after an upgrade to v4.1.17)
Actual behaviour
It gives this error:
Steps to reproduce
Just bind to a struct with a primitive.ObjectID
Working code to debug
Version/commit
v4.1.17
The text was updated successfully, but these errors were encountered: