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

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

使用 gocosmos 創(chuàng)建文檔時未經(jīng)授權(quán)

使用 gocosmos 創(chuàng)建文檔時未經(jīng)授權(quán)

Go
拉風(fēng)的咖菲貓 2022-09-05 09:59:45
我從 https://github.com/btnguyen2k/gocosmos 那里得到了Azure CosmosDB的go-sql-driver。當(dāng)我打電話給gocosmos時,它很順利。NewRestClient 獲取 rest 客戶端,CreateDatabase() 創(chuàng)建數(shù)據(jù)庫,CreateCollection() 創(chuàng)建集合。問題是當(dāng)我使用CreateDocument()時,我得到狀態(tài)碼401和正文的響應(yīng),如下所示{"code":"Unauthorized","message":"The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'post\ndocs\ndbs/ToDoList/colls/Items\nmon, 31 may 2021 13:31:44 gmt\n\n'\r\nActivityId: a9bbd729-3495-400f-9d79-ddec3737aa92, Microsoft.Azure.Documents.Common/2.11.0"}我已經(jīng)嘗試了我見過的所有解決方案,但我還沒有解決問題。
查看完整描述

1 回答

?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊

我按照本教程進(jìn)行了操作,使用此示例代碼,我可以成功創(chuàng)建數(shù)據(jù)庫,集合和文檔。這是我的測試結(jié)果,它能幫到你嗎?

http://img1.sycdn.imooc.com//6315582c0001e31809870576.jpg

// connects to MongoDB

func connect() *mongo.Client {

    mongoDBConnectionString := os.Getenv(mongoDBConnectionStringEnvVarName)

    if mongoDBConnectionString == "" {

        log.Fatal("missing environment variable: ", mongoDBConnectionStringEnvVarName)

    }


    database = os.Getenv(mongoDBDatabaseEnvVarName)

    if database == "" {

        log.Fatal("missing environment variable: ", mongoDBDatabaseEnvVarName)

    }


    collection = os.Getenv(mongoDBCollectionEnvVarName)

    if collection == "" {

        log.Fatal("missing environment variable: ", mongoDBCollectionEnvVarName)

    }


    ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)

    defer cancel()


    clientOptions := options.Client().ApplyURI(mongoDBConnectionString).SetDirect(true)

    c, err := mongo.NewClient(clientOptions)


    err = c.Connect(ctx)


    if err != nil {

        log.Fatalf("unable to initialize connection %v", err)

    }

    err = c.Ping(ctx, nil)

    if err != nil {

        log.Fatalf("unable to connect %v", err)

    }

    return c

}


// creates a todo

func create(desc string) {

    c := connect()

    ctx := context.Background()

    defer c.Disconnect(ctx)


    todoCollection := c.Database(database).Collection(collection)

    r, err := todoCollection.InsertOne(ctx, Todo{Description: desc, Status: statusPending})

    if err != nil {

        log.Fatalf("failed to add todo %v", err)

    }

    fmt.Println("added todo", r.InsertedID)

}


查看完整回答
反對 回復(fù) 2022-09-05
  • 1 回答
  • 0 關(guān)注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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