-
Notifications
You must be signed in to change notification settings - Fork 14
/
load_users_with_id_less_than_1000.go
58 lines (45 loc) · 1.15 KB
/
load_users_with_id_less_than_1000.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Working for Firestore database:
collection: users
>> document: "auto_id"
--customer_id: 111
>> document: "auto_id"
--customer_id: 123
>> document: "auto_id"
--customer_id: 4500
>> document: "auto_id"
--customer_id: 3500
where 'customer_id' is defined as number type
*/
package main
import (
"context"
"fmt"
"log"
"google.golang.org/api/iterator"
"cloud.google.com/go/firestore"
)
func main() {
fmt.Println("Started Firestore app")
// Sets your Google Cloud Platform project ID.
projectID := "[PROJECT_ID]"
// Get a Firestore client.
ctx := context.Background()
client, err := firestore.NewClient(ctx, projectID)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
iter := client.Collection("users").Where("customer_id", "<", 1000).Documents(ctx)
for {
doc, err := iter.Next()
if err == iterator.Done {
break
}
if err != nil {
log.Fatalf("Failed to iterate: %v", err)
}
fmt.Println(doc.Data())
}
// Close client when done.
defer client.Close()
}