duanposhi3641 2016-09-04 21:27
浏览 221
已采纳

使用Golang在MongoDb中插入嵌套结构

I have a question regarding storage in MongoDB using mgo. My DB has this structure :

{ "Arrival": [ "04-09-2016" ], "Clicks": [ "56ffd41d9c8c9adf088b4576", "4f1dc63a7c2d3817640000a1" ], "Recherches": [ "érysipèle" ], "abonnements": { "newsletter": false }, "compte": "Standard", "datei": ISODate("2016-09-04T14:55:39.179Z"), "email": "_°°°°_", "mdp": "27d8d166ca1f1715541b7df6453401b95a1d59c2ca0f60ce71037d33926c4d6f09a63a909a8d5cb5230f92584973a4dd2b8bcf155d5785ef7e2afdd113334eee", "type": "T&D", "user": "_°°°°_", "validation": "validé" }

In my Go application the structures are :

My structures are :

type Abonnement struct {
    Newsletter bool bson:"newsletter"'
  }

type Persone struct {
    Compte string 'bson:"compte"'
    Datei time.Time 'bson:"datei"'
    Email string  'bson:"email"'
    MDP string 'bson:"mdp"'
    Type string 'bson:"T&D"'
    User string 'bson:"user"'
    Validation string 'bson:"validation"'
    Arrival []string 'bson:"Arrival"'
    Clicks []string 'bson:"Clicks"'
    Recherches []string 'bson:"Recherches"'
    Abonnements []Abonnement 'bson:"abonnements"'
  }

But I can't manage to create the variable to put everything together :

personita := Persone{ Compte : "Standard", Datei : time.Date(2015, time.February, 12, 04, 11, 0, 0, time.UTC), Email : "test@test.com", MDP : "test_mdp", Type : "T&D", User : "test_user", Validation : "validé", Arrival : []string{}, Clicks : []string{}, Recherches : []string{}, Abonnements : []Abonnement{}, }

My main goal would be that there's a default value when I insert 'personita' with this inside : "abonnements": { "newsletter": false }

  • 写回答

3条回答 默认 最新

  • dongyipa0028 2016-09-04 21:33
    关注

    Seems just a typo

    Abonnements : []Abonnement{}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并