The problem I face at the minute is trying to select a nested object array so that I can append data to it or just insert into it. The following is the json in Mongo i'm trying to query:
{
"username":"tester@tester.com",
"Course":[
{
"Date":{
"DatePlayed":"Fri Jul 21 2017 00:00:00 GMT 0100 (GMT Daylight Time)",
"Course":{
"CoursePlayed":"testerCourse",
"holes":[
{
"holeno":0,
"score":"",
"putts":"",
"penalty":"",
"bunker":"",
"green":"",
"fairway":""
}
]
}
}
}
]
}
What I am trying to do is select the object within the holes array so that I can either append or just enter data into the object. The structs that I am using are as follows:
type Hole struct {
Holeno int64 `json:"holeno" bson:"holeno"`
Score string `json:"score" bson:"score"`
Putts string `json:"putts" bson:"putts"`
Penalty string `json:"penalty" bson:"penalty"`
Bunker string `json:"bunker" bson:"bunker"`
Green string `json:"green"bson:"green"`
Fairway string `json:"fairway"bso n:"fairway"`
}
type Round struct {
Date struct {
DatePlayed string `json:"DatePlayed" bson:"DatePlayed"`
Course struct {
CoursePlayed string `json:"CoursePlayed" bson:"CoursePlayed"`
Holes [18]Hole `json:"Hole" bson:"Hole"`
} `json:"Course" bson:"Course"`
} `json:"Date" bson:"Date"`
}
The attempt I have made so fair which has failed is as follows
err = u.Find(bson.M{"username": Uname}).Select(bson.M{"Course.Date.Course.holes": 1}).One(&Game)
Game is just Game:=Round{}