gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 03:05:48 25 4
gpt4 key购买 nike

我对使用 mgo 在 MongoDB 中存储有疑问。

我的数据库有这样的结构:

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

在我的 Go 应用程序中,结构是:

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

但我无法创建变量来将所有内容放在一起:

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

我的主要目标是当我在里面插入'personita'时有一个默认值:

"abonnements": {
"newsletter": false
}

最佳答案

似乎只是一个错字

Abonnements : []Abonnement{}

关于mongodb - 使用 Golang 在 MongoDb 中插入嵌套结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39321653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com