第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當鍵包含大寫時,無法使用 mgo 檢索值

當鍵包含大寫時,無法使用 mgo 檢索值

Go
瀟湘沐 2021-10-18 16:13:05
來自 mongoDB 的一項數(shù)據(jù)是{    "_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."}在我的代碼中,結(jié)構(gòu)是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如果是大寫的,就出問題了。我該如何解決這個問題?
查看完整描述

1 回答

?
冉冉說

TA貢獻1877條經(jīng)驗 獲得超1個贊

字段標記中存在語法錯誤。刪除字段標記中 ':' 和 '"' 之間的空格。

TimeStamp   string `bson:"timeStamp" json:"timeStamp"`

字段標記的語法是無情的。

與此問題分開,您可能應該添加

ID bson.ObjectId `bson:"_id"`

應用程序可以訪問該結(jié)構(gòu)的對象 id。


查看完整回答
反對 回復 2021-10-18
  • 1 回答
  • 0 關(guān)注
  • 199 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號