I am new to fireStore and trying to retrieve document values but it isn't working as I would expect. I am getting a "permission denied" when trying to access through my IDE and golang.
Code:
func TestConnectToCollection(t *testing.T) {
ctx := context.Background()
client, err := firestore.NewClient(ctx, "<my-Project-ID>")
if err != nil {
// TODO: Handle error.
}
defer client.Close()
doc := client.Doc("profile/test3")
fmt.Println(doc)
fmt.Println(doc.ID)
iter := client.Collection("profile").Documents(ctx)
for {
doc, error := iter.Next()
if error == iterator.Done {
break
}
if error != nil {
fmt.Println(error.Error())
} else {
fmt.Println(doc.Data())
}
}
}
Output:
&{0xc0001725a0 projects/<project-id>/databases/(default)/documents/profile/test3 test3}
test3
rpc error: code = PermissionDenied desc = Missing or insufficient permissions.
rpc error: code = PermissionDenied desc = Missing or insufficient permissions.
rpc error: code = PermissionDenied desc = Missing or insufficient permissions.
rpc error: code = PermissionDenied desc = Missing or insufficient permissions.
Firestore rules - I opened up my firestore rules thinking that was the issue.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}