'How do I access data from a top-level document in a Cloud firestore trigger with Cloud functions?

Example: If my trigger is onWrite on a path such as Users/{userId}/Billings/{billingId}, how can I access user document data:

.onWrite((change, context) => {


I know that I can access billing data via change and wild cards userId and billingId via context.params.

How would I access user document data that triggered this?

Solution 1:[1]

You can't directly get the user document from the parameters. But you can determine the path from the parameters, and then load the document with the Admin SDK.



This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen