选择嵌套数组对象-Mgo

时间:2017-03-02 11:43:51

标签: mongodb go

我现在面临的问题是尝试选择一个嵌套的对象数组,以便我可以将数据附加到它或只是插入它。以下是Mongo的json我试图查询:

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"`
} 

我要做的是选择孔数组中的对象,以便我可以追加或只是将数据输入到对象中。我使用的结构如下:

err = u.Find(bson.M{"username": Uname}).Select(bson.M{"Course.Date.Course.holes": 1}).One(&Game)

我做出如此公平的失败的尝试如下

{{1}}

游戏只是游戏:=回合{}

0 个答案:

没有答案