firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.13k stars 244 forks source link

Unable to add nested structs to Firestore #405

Closed akshaybabloo closed 3 years ago

akshaybabloo commented 3 years ago

Describe your environment

[REQUIRED] Describe the problem

I am having issue showing the data that is part to nested struct. Example:

import (
    "context"

    firebase "firebase.google.com/go/v4"
    "google.golang.org/api/option"
)

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"`
}

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)
    }
}

Above code should be able to do something like this:

name: "Test"
status:
     title: "hello"
     message: "hi"

But I get (screenshot)

Screen Shot 2020-10-10 at 6 20 03 PM

Note that Status is not a sub collection, it is a part of the main collection

google-oss-bot commented 3 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

akshaybabloo commented 3 years ago

Any uppdate on this?

schmidt-sebastian commented 3 years ago

Sorry - we don't own the Firestore Go client, but merely wrap it. Do you mind filing the issue at https://github.com/googleapis/google-cloud-go?