Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are changes in sub-collections are supposed to trigger onWrite function or not?

Can Firebase functions be triggered by a change in subcollections when the function is listening to a top level document? If not, what does the first line in the wildcard examples of the documentation mean?

What does this mean??? if a sub-collection changes would it trigger the function? But it doesn't seem to and somewhere else in the same page says that too.

// Listen for changes in all documents and all sub-collections

...

exports.useWildcard = functions.firestore
  .document('users/{userId}')
  .onWrite((event) => {
    // If we set `/users/marie` to {name: "marie"} then
    event.params.userId == "marie"
    // ... and ...
    event.data.data() == {name: "Marie"}
  });

What is the intended behavior for Firestore and function triggers?

like image 248
TheeBen Avatar asked Dec 14 '22 18:12

TheeBen


1 Answers

I believe the comment in the sample code is incorrect for the sample whose document wildcard is this:

'users/{userId}'

Note that in the text below that sample it says:

If a document in users has subcollections, and a field in one of those subcollections' documents is changed, the userId wildcard is not triggered.

The sample below it with the following wildcards:

'users/{userId}/{messageCollectionId}/{messageId}'

will be triggered only when documents in any subcollection of documents in users are written (not the documents immediately within users).

Feel free to file a bug report for documentation or sample that you've for to be incorrect.

like image 144
Doug Stevenson Avatar answered Jun 03 '23 22:06

Doug Stevenson