I’m reading the documentation of Extend Cloud Firestore with Cloud Functions.
The code is as follows
// Listen for changes in all documents in the 'users' collection
exports.useWildcard = functions.firestore
.document('users/{userId}')
.onWrite((change, context) => {
// If we set `/users/marie` to {name: "Marie"} then
// context.params.userId == "marie"
// ... and ...
// change.after.data() == {name: "Marie"}
});
In functions.firestore.document('users/{userId}')
, I don’t really understand the {userId}
.
I know every collection in firestore has a document ID. I have saved my document ID in the field of every user as UID
. So, do I replace the {userId}
with my UID
or I should just use the {userId}
as it it or do I need to use the specific field I want to trigger?
In my case I want to trigger the field time
in my document.
The {userId}
in the triggering path means that the function is triggered by any document under users
, and that the document ID is available in your code as context.params.userId
.