Attached is snapshot of Firebase dataStore portal followed by code. The code works and returns map of a Document.
Question: How would I get a specific field in a Document? For example, size? instead of returning map of Document,
Put another way... how could I return this... [Collection01][Document01][SPECS][Size] = string
or this... [Collection01/Document01/SPECS/Size] = string
Firebase Portal
GOLANG CODE
package main
import (
"fmt"
"log"
"golang.org/x/net/context"
firebase "firebase.google.com/go"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
func main() {
ctx := context.Background()
sa := option.WithCredentialsFile("./scaiqit55-fb.json")
app, err := firebase.NewApp(ctx, nil, sa)
if err != nil {
log.Fatalf("error initializing app: %v
", err)
}
client, err := app.Firestore(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Close()
iter := client.Collection("Collection01").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...
// nacsid := doc.Ref.ID
docdata := doc.Data()
fmt.Println("------NEW INDEX----------")
fmt.Println(doc.Ref.ID)
fmt.Println(docdata)
// Returns...
// ------NEW INDEX----------
// Document01
// map[SPECS:map[Color:red SIZE:Large]]
//---------------------------
// My question is here...
// How would i return...
// [Collection01][Document01][SPECS][Size]
// and just get a string of "large"
// this is where the answer would go...
}
}