I'm working on a project that based on MongoDB data structure. Our objects that stored inside the database looks like this:
{
"_id" : ObjectId("567a877df1c7720bea7c2f51"),
"username" : "dog",
"type" : "regular",
"data" : {
"full" : {
"xx" : "xx",
"xx" : "xx",
"yy" : {
"xx" : "test"
},
"yy" : {
"xx" : {
}
}
}
}
And the struct that we working on with Golang looks like this:
type User struct {
Id bson.ObjectId `bson:"_id,omitempty"`
username string
Type string
data struct {
full struct {
xx string `json:"xx"`
xx string `json:"xx"`
xxx struct{} `json:"xx"`
yy struct {
}
}
}
}
The thing is that the first properties gets fill with data without any problem but the objects inside the object are not working.
Our code to pull data is the regular code as we saw in the MGO documentation.
err = collection.Find(bson.M{"username": username}).One(&user)
Is there any specific way to fetch the data in that way?