我有这样的结构:
type ArticleDocument struct {
ArticleID string `json:"article_id" bson:"article_id"`
ArticleTitle string `json:"article_title" bson:"article_title"`
Author string `json:"author" bson:"author"`
Board string `json:"board" bson:"board"`
Content string `json:"content" bson:"content"`
Date string `json:"date" bson:"date"`
IP string `json:"ip" bson:"ip"`
MessageConut struct {
All int `json:"all" bson:"all"`
Boo int `json:"boo" bson:"boo"`
Count int `json:"count" bson:"count"`
Neutral int `json:"neutral" bson:"neutral"`
Push int `json:"push" bson:"push"`
} `json:"message_count,inline" bson:"message_count,inline"`
Messages []interface{} `json:"messages" bson:"messages"`
URL string `json:"url" bson:"url"`
}
在MongoDB中,我的文档如下:
{
"_id" : ObjectId("5ab1da8133691b034b2be31d"),
"article_id" : "M.1521548086.A.DCA",
"article_title" : "some title",
"author" : "somebody",
"board" : "some board",
"content" : "some content",
"date" : "Tue Mar 20 20:14:42 2018",
"ip" : "1.1.1.1",
"message_conut" : {
"all" : 15,
"boo" : 0,
"count" : 14,
"neutral" : 1,
"push" : 14
},
"messages" : [],
"url" : "https://xxx.xxx.xxx"
}
在我的Golang代码中,我尝试使用mgo查询此文档并将其打印出来,但是,除了嵌套文档" MessageConut"之外,所有文档字段都正确转换为golang结构,所有值in" All"," Boo"," Count",...等为零:
message_count":{"all":0,"boo":0,"count":0,"neutral":0,"push":0}"
请您指导我如何解决此问题?