0

According to the official documentation, it is quite possible to setup a cloud function that will be invoked on a change in the datastore ( a new document added etc ). However it looks like this functionality is defined for Firestore mode, unless I am missing something.

For starters, I created a simple Go function that is aimed to print the event object to logs:

package dblog

import (
    "context"
    "fmt"

    "cloud.google.com/go/functions/metadata"
)

func DbWatch(ctx context.Context, e map[string]interface{}) error {
    meta, err := metadata.FromContext(ctx)
    if err != nil {
        return fmt.Errorf("metadata.FromContext: %v", err)
    }
    fmt.Printf("%#+v\n%#+v", *meta, e)
    return nil
}

I deployed it with

gcloud functions deploy dbwatch --entry-point DbWatch --trigger-event providers/cloud.firestore/eventTypes/document.create --trigger-resource "projects/MYPROJECTIDHERE/databases/(default)/documents/trigger/{triggerid}" --runtime go111 --memory 128MB

So far the function is there, but if I create a document with the kind trigger - there is no invocation record at all. Either I am missing something about the resource specification for datastore, or triggers are not implemented.

1 Answer 1

1

I understand your Cloud Function created for a Firestore document in Datastore mode is not being triggered as expected.

This is indeed intended behavior, as mentioned in the "Limitations and guarantees" section of the public documentation[1], Cloud Functions triggers for Firestore are only available in native mode.

As such you may use Cloud Functions to monitor changes in Firestore native documents only. To make use of this feature you will need to create a new project with Firestore in Native mode[2].

[1] https://cloud.google.com/functions/docs/calling/cloud-firestore#limitations_and_guarantees

[2] https://cloud.google.com/datastore/docs/firestore-or-datastore#choosing_a_database_mode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.