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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 Go 將結(jié)構(gòu)插入到 Mongodb 中

使用 Go 將結(jié)構(gòu)插入到 Mongodb 中

Go
有只小跳蛙 2022-06-06 16:07:19
我想將如下所示的數(shù)據(jù)結(jié)構(gòu)插入到 MongoDB{    "rolecode": "DHBK1_ROLE_04",    "functioncodelist": [        "DHBK1_FUNC_1",        "DHBK1_FUNC_2",          .....        "DHBK1_FUNC_n"]    "productid": "ABC_Platform",    "comid": "DHBK1"}這是我的代碼:package mainimport (    "context"    "gopkg.in/mgo.v2")func main() {    insertObj()}type CompanyRoleFunction struct {    Rolecode         string `json:"rolecode"`    Productid        string `json:"productid"`    Functioncodelist []string    Comid string `json:"comid"`}func insertObj() {    session, err := mgo.Dial("mongodb://casuser:Mellon@222.255.102.145:27017/users")    if err != nil {    panic(err)    }    c := session.DB("users").C("company_role_function")    var companyRoleFunction CompanyRoleFunction    companyRoleFunction.Rolecode = "DHBK1_ROLE_05"    companyRoleFunction.Productid = "XYZ_Platform"    companyRoleFunction.Comid = "DHBK1"    err = c.Insert(companyRoleFunction)    if err != nil {        fmt.Println(err)    }}我的代碼已經(jīng)運(yùn)行,但它只插入這樣的結(jié)構(gòu)(當(dāng)然,因?yàn)槲也恢廊绾翁幚頂?shù)組 Functioncodelist )[![在此處輸入圖像描述][1]][1]這是我的數(shù)據(jù),我希望插入{"_id":{"$oid":"5ed0c2e2402a000037004c84"},"rolecode":"DHBK1_ROLE_07","functioncodelist":["DHBK1_FUNC_1","DHBK1_FUNC_2"],"productid":"ABC_Platform","comid":"DHBK1"}
查看完整描述

1 回答

?
郎朗坤

TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個(gè)贊

它沒有顯示在數(shù)據(jù)庫中,因?yàn)槟迦氲奈臋n不包含任何值。在你的 go 代碼中設(shè)置一個(gè)值,它應(yīng)該在數(shù)據(jù)庫中顯示得很好,除非我誤解了你的問題。


...

type Functioncode string

...

companyRoleFunction.Functioncodelist = make(map[string]Functioncode)

...

companyRoleFunction.Functioncodelist["foo"] = "bar"

...

有關(guān) Go 地圖的快速介紹,請(qǐng)參見https://tour.golang.org/moretypes/19。


查看完整回答
反對(duì) 回復(fù) 2022-06-06
  • 1 回答
  • 0 關(guān)注
  • 190 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

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