【发布时间】:2016-12-10 04:46:32
【问题描述】:
我的 mongo 收藏中有这类文档 -
{
"_id" : "3wPEpWwECbrTrnSbh",
"brandId" : 45,
"title" : "brandtitle",
"logoImg" : "brandtitle.png",
"category" : {
"category 1" : [
{
"cat" : "A1 Plus Champ"
},
{
"cat" : "A108"
},
{
"cat" : "A6"
},
],
"category 2" : [
{
"cat" : "something"
},
{
"cat" : "soemthing else"
},
{
"cat" : "something else"
},
],
},
"isActive" : true,
"isOnboarded" : false,
"serviceNumber" : 18605001492.0
}
所以有几个品牌。 我可以得到所有东西,除了这个中的类别。
我的模型代码数据类型是 -
type Brand struct {
Id string `bson:"_id" json:"_id"`
Brandid int `bson:"brandId" json:"brandId"`
Title string `json:"title"`
Logoimg string `bson:"logoImg" json:"logoImg"`
Category []string `bson:"category" json:"category"`
Isactive bool `bson:"isActive" json:"isActive"`
Isonboarded bool `bson:"isOnboarded" json:"isOnboarded"`
Servicenumber int `bson:"serviceNumber" json:"serviceNumber"`
}
我现在把 Category 当作一个字符串数组,但这当然是错误的。
输出看起来像这样 -
{
"_id": "3wPEpWwECbrTrnSbh",
"brandId": 45,
"title": "brandtitle",
"logoImg": "brandtitle.png",
"category": null,
"isActive": true,
"isOnboarded": false,
"serviceNumber": 18605001492
}
我应该如何构造这个结构来显示我从数据库中获取的数据类型?
【问题讨论】:
标签: mongodb go struct mgo revel