亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

Google Datastore 無效密鑰錯誤

Google Datastore 無效密鑰錯誤

Go
桃花長相依 2023-03-21 17:09:08
我正在嘗試使用 golang 將項目放入 Google 數據存儲區。雖然我總是遇到datastore: invalid key錯誤,但無法弄清楚這里出了什么問題。我正在使用這個"cloud.google.com/go/datastore"包。首先,我嘗試獲取父節點的密鑰(不確定這是正確的方法,但我最終得到了一個datastore.Keyas parentKey)?,F在,當使用 as parent 創建一個新密鑰parentKey,然后嘗試使用put該項目時,newKey我收到了invalid key錯誤消息。q := datastore.NewQuery("Supplier")              .Namespace("inventory")              .Filter("Name =", "supplier-01")              .Limit(1)var s []supplierparentKey, err := client.GetAll(ctx, q, &s)if err != nil || len(parentKey) < 1 {    fmt.Printf("could not find parent key: %v\n", err)    return}newKey := datastore.IncompleteKey("InventoryItem", parentKey[0])//newKey := datastore.NameKey("InventoryItem", item.Name, parentKey[0])if _, err := client.Put(ctx, newKey, &item); err != nil {    fmt.Printf("could not save item: %v\n", err)    return}NameKey我用和都試過了,IncompleteKey但都沒有運氣。我顯然在這里遺漏了一些東西,但無法弄清楚它是什么以及如何將我的項目作為另一個節點的子節點寫入數據存儲區。
查看完整描述

1 回答

?
SMILET

TA貢獻1796條經驗 獲得超4個贊

湯米,你在評論中指出了這一點。您需要在新密鑰上設置名稱空間。我在Cloud Datastore Go 文檔中看不到隱式執行此操作的方法,因此您必須在調用 Put() 之前執行 newKey.namespace = parentKey.namespace。



查看完整回答
反對 回復 2023-03-21
  • 1 回答
  • 0 關注
  • 90 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號