RobrechtVM
RobrechtVM

Reputation: 946

Multiple triggers on the same firestore collection

Is it allowed to have multiple onWrite triggers on the same firestore collection? I already have one onWrite event in my cloud functions:

exports.modifyUser = functions.firestore.document('users/{userId}')
.onWrite((change, context) => {
...
}

Is it ok to have another one? I know I could combine it in the same trigger but my application is in production already and I really don't want to break anything by messing up the existing database trigger.

Upvotes: 5

Views: 1909

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600116

Yes, it is totally acceptable to have multiple triggers on the same collection. They'll fire independently of each other, and run on different containers.

Note that you'll pay extra for having them isolated, as running them separate doubles the number of invocations, and probably reduces your options for running code in parallel (which would reduce the the CPU and GB seconds).

Upvotes: 8

Related Questions