Could you help to see what happen in my code?
Hi Phong,
Ignoring some of the missing structs/data on your example i.e. Profile. Given the JSON document sample with the following class mappings:
type User struct
{
ID primitive.ObjectID `json:"ID" bson:"_id"`
UserName string `json:"UserName"`
Connections []Connection `json:"Connections",bson:"connections"`
}
type Connection struct
{
OrganisationID primitive.ObjectID `json:"OrganisationID" bson:"organisationid"`
UpdatedDateUTC string `json:"UpdatedDateUTC,omitempty"`
}
You should be able to decode Connection
as below:
userDoc := User{}
err = collection.FindOne(ctx, bson.M{}).Decode(&userDoc)
fmt.Println(userDoc.Connections)
If you are still encountering issues with this, please provide:
Regards,
Wan.