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

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

如何返回文檔索引名稱值

如何返回文檔索引名稱值

Go
拉風的咖菲貓 2023-04-17 16:07:40
這是一個 GoLang,Firebase AdminSDK 問題。此示例用于循環訪問 FireStore 數據庫中的所有文檔。我怎樣才能得到文檔名稱?換句話說:如果集合名稱是JohnyCollection,并且JohnyCollection有 20 個名為 ( Document1, Document2.... Document20) 的文檔,我如何在 golang 代碼中獲取文檔名稱?//========================================package mainimport (    "context"    "fmt"    "log"    "firebase.google.com/go"    "google.golang.org/api/iterator"    "google.golang.org/api/option")func check(e error) {    if e != nil {        panic(e)    }}func main() {    ctx := context.Background()    sa := option.WithCredentialsFile("./scai-qit-fb-adminsdk.json")    app, err := firebase.NewApp(ctx, nil, sa)    if err != nil {        log.Fatalf("error initializing app: %v\n", err)    }    client, err := app.Firestore(ctx)    if err != nil {        log.Fatal(err)    }    defer client.Close()    iter := client.Collection("COMPLEX_NONACS").Documents(ctx)    for {        doc, err := iter.Next()        if err == iterator.Done {            break        }        if err != nil {            log.Fatalf("Failed to iterate: %v", err)        }        //This part works.  WIll return a Map of each Document        fmt.Println("--------------------------/n")        fmt.Println(doc.Data())        //  This is the question.  How do I get the INDEX name of the Document?        //  something like...        fmt.Println(doc.Index_value_or_something_that_returns_IndexName())        //  for example...        // {        // "ABC":{"line1":"yabba dabba","line2":"dingo dong"},        // "DEF":{"line1":"hooty tooty","line2":"blah blah"}        // }        // How to just get the "ABC"  and "DEF"    }}
查看完整描述

1 回答

?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

DocumentSnapshot您可以通過首先查找 來從 獲取文檔 ID?DocumentRef

?fmt.Println(doc.Ref.ID)


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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