来自 mongoDB 的一项数据是
{
"_id" : ObjectId("5536def4e4b0644323e219a8"),
"title" : "The Title",
"description" : "The Description",
"timeStamp" : "21/04/2015",
"category" : "news",
"url" : "http://www.example.com",
"source" : "Evening Times",
"mainStory" : "This is the main story."
}
在我的代码中,结构是
type NewsData struct {
Title string `bson: "title" json: "title"`
TimeStamp string `bson: "timeStamp" json: "timeStamp"`
Description string `bson: "description" json: "description"`
MainStory string `bson: "mainStory" json:"mainStory"`
}
然后我用下面的代码来提取信息
err = conn.Find(nil).Select(bson.M{"title": 1, "timeStamp": 1, "description": 1, "mainStory": 1}).All(&result)
但是,当我打印result出来时,timeStampand 的mainStory值为空。我查了文档,说mgo是把key取小写的,所以mongoDB的key如果是大写的,就出问题了。
我该如何解决这个问题?
冉冉说
相关分类