Here is how my mongoDb document looks like:
{
"_id": 111,
"updateDate": "2000-10-01T04:00:00Z",
"updateLogs": [
[
{
"updatedBy": "user1",
"updatedDate": "2020-06-23T21:23:37.138Z",
"info": "test"
},
{
"updatedBy": "user1",
"updatedDate": "2020-06-23T21:23:37.138Z",
"info": "test2"
}
],
[
{
"updatedBy": "user2",
"updatedDate": "2020-06-23T21:23:37.138Z",
"info": "test"
},
{
"updatedBy": "user2",
"updatedDate": "2020-06-23T21:23:37.138Z",
"info": "test2"
}
]
]
}
and this is how I try to define struct to use for such document:
type DocumentsData struct {
Id int32 `bson:"_id" json:"_id"`
UpdateDate time.Time `bson:"updateDate" json:"updateDate"`
UpdateLogs [][]LogValue `bson:"updateLogs,omitempty" json:"updateLogs,omitempty"`
}
type LogValue struct {
UpdatedBy string `bson:"updatedBy" json:"updatedBy"`
UpdatedDate time.Time `bson:"updatedDate" json:"updatedDate"`
Info string `bson:"info" json:"info"`
}
and here is how I retrieve the documents:
var myDocuments []DocumentsData
cur, err := docCollection.Find(context.TODO(), bson.D{}, &options.FindOptions{})
for cur.Next(ctx) {
var myDoc DocumentsData
cur.Decode(&myDoc)
myDocuments = append(myDocuments, myDoc)
}
but for some reason it doesn't build nested arrays in response. Please advise whether my struct definition is correct for such document structure