1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| func Query() { ctx := context.Background(); client := CreateFirestoreClient(ctx) defer client.Close() query := client.Collection("path").Where("data_id", "==", "1") iter := query.Documents(ctx) for { doc, err := iter.Next() if err == iterator.Done { break } if err != nil { log.Fatalf("Failed to iterate: %v", err) } data := doc.Data() jsonbuf, _ := json.Marshal(data) jsonpb.Unmarshal(bytes.NewReader(jsonbuf), &pbObj) } }
|