我正在嘗試向 Firestore 添加一個嵌套結構,由于某種原因,添加的內容都是非結構,看起來像:結構看起來像這樣:type Status struct { Title string `json:"title,omitempty" firestore:"title,omitempty"` Message string `json:"message,omitempty" firestore:"title,omitempty"`}type Config struct { Name string `json:"name,omitempty" firestore:"name,omitempty"` Status Status `json:"status,omitempty" firestore:"status,omitempty"`}代碼看起來像這樣:import ( "context" firebase "firebase.google.com/go/v4" "google.golang.org/api/option")func main() { configuration := Config{ Name: "Test", Status: Status{ Title: "hello", Message: "hi", }, } ctx := context.Background() config := firebase.Config{ ProjectID: "", StorageBucket: "", } opt := option.WithCredentialsFile("firebase_config.json") app, err := firebase.NewApp(ctx, &config, opt) if err != nil { panic(err) } // Get an auth client from the firebase.App client, err := app.Firestore(ctx) if err != nil { panic(err) } _, _, err = client.Collection("forecast").Add(ctx, configuration) if err != nil { panic(err) }}上面的代碼僅適用于不在嵌套結構中的元素。對此的任何幫助將不勝感激更新 1Status不是子集合而是對象,例如:{ "name": "Test", "status": { "title": "hello", "message": "hi" }}
將嵌套結構添加到 Firestore
慕尼黑8549860
2022-07-11 10:27:26