0

I was trying to use EventArc to monitor Firestore changes, which will trigger a Cloud Run service.

It works by listening to Any Resource or specific resource name.

Resource name
projects/PROJECT_Id/databases/(default)

enter image description here

It works, but it will listen to all changes in firestore. However, I want to filter the event to a specific collection. I have tried a few combinations to the pattern, and none of them works. E.g.

projects/PROJECT_Id/databases/(default)/users/*
projects/PROJECT_Id/databases/(default)/users/{user}

Any ideas? Thanks :)

Dale Nguyen
  • 1,930
  • 3
  • 24
  • 37

1 Answers1

0

I have seen in the image you shared, under the “Resource” section you selected “specific resource” instead can you try to change it to a “path pattern” and you will be able to write a specific path that the trigger object needs to respect.

You can refer to this documentation for Applying a path pattern when filtering in Eventarc.

You can also check out the AuditLog step of Trigger Cloud Run with events from Eventarc codelab for an example on how to use path patterns.

  • Thanks, even though in the image I set specific resource. I did it with the same configuration for the path pattern. It doesn't return anything. Does it work for you? – Dale Nguyen Dec 06 '22 at 16:44
  • Instead of giving default, can you try giving the database ID in place of default like if your databaseId is demo then your database will be having path databases/demo – Sandeep Vokkareni Dec 08 '22 at 08:18
  • Meanwhile try with this path: `projects/PROJECT_ID/databases/(default)/documents/users/{userId}` for any changes to a document in users collections having userId – Sandeep Vokkareni Dec 08 '22 at 08:23
  • There's no event yet. I think they're not supported for firestore yet. – Dale Nguyen Dec 10 '22 at 09:03
  • 2
    Yes, you are correct. As per the [documentation](https://cloud.google.com/functions/docs/calling/cloud-firestore#specifying_the_document_path) To trigger the function, specify a document path to listen to. Functions only respond to document changes, and cannot monitor specific fields or collections. – Sandeep Vokkareni Dec 12 '22 at 14:27