doucao1066 2017-03-02 11:43
浏览 19

选择嵌套数组对象-Mgo

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{}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大