fix(firestore): create doc before updating
After the test for this snippet was failing because the
snippet updated a doc which had not yet been created. This adds
the doc creation to the same function (but outside the region tag).
Fixes
@@ -124,8 +124,15 @@ func addDocAfterAutoGeneratedID(ctx context.Context, client *firestore.Client) e
}
func updateDoc(ctx context.Context, client *firestore.Client) error {
+ _, err := client.Collection("cities").Doc("DC").Set(ctx, map[string]interface{}{
+ "name": "District of Columbia",
+ "country": "USA",
+ })
+ if err != nil {
+ log.Printf("adding city DC: %s", err)
+ }
// [START fs_update_doc]
- _, err := client.Collection("cities").Doc("DC").Update(ctx, []firestore.Update{
+ _, err = client.Collection("cities").Doc("DC").Update(ctx, []firestore.Update{
{
Path: "capital",
Value: true,
