[GODRIVER-1182] FindOne.Decode not decoding embedded struct fields Created: 02/Jul/19 Updated: 09/Jul/19 Resolved: 09/Jul/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | 1.0.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | prakash | Assignee: | Emmanuel Eppinger (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux-ubuntu |
||
| Description |
|
I have this following structure in my collection
I am using the following struct (Address struct embedded)
So, When I do
I am getting the userID, Name and Email field but the address fields are blank.
And when I am using this user struct, everything is working fine and I am getting all data from MongoDB as required.
|
| Comments |
| Comment by Daniel Mejia R [ 09/Jul/19 ] | ||||||||||||
|
Thanks Manny, so I'd need to use something like this,
In order to have
Thanks in advance
| ||||||||||||
| Comment by Emmanuel Eppinger (Inactive) [ 09/Jul/19 ] | ||||||||||||
|
Hi All,
You should be able to use the `bson:"inline"` struct tag to enable this behavior.
Thanks and let us know if you have any more questions Emmanuel
| ||||||||||||
| Comment by Daniel Mejia R [ 03/Jul/19 ] | ||||||||||||
|
I've found that this behaviour could be related to the decoder used by BSON itself That's all I can say. I'm not saying is an issue with mongo, I just added additional information that might be related with the behaviour you are reporting, but we must wait for the dev-team to take on the issue | ||||||||||||
| Comment by prakash [ 03/Jul/19 ] | ||||||||||||
|
Hey @Daniel, I am confused. The problem is with MongoDB or I have to fix something in my application. | ||||||||||||
| Comment by Daniel Mejia R [ 02/Jul/19 ] | ||||||||||||
|
I've found that this behaviour could be related to the decoder used by BSON itself when dealing with embeded structs. Take a look for instance at the behaviour of the following: https://play.golang.org/p/OBbfb_6jPjH At the database you would expect to have
But instead I'm having
Which is counter-intuitive given the standard behaviour for embeded structs and json Decoding |