Milton
Milton

Reputation: 968

How to use dynamic reference triggers in Cloud Functions for Firebase

I would like to know how to change dynamically the reference of a Realtime Database trigger.

For example, I would like to add the current date at the beginning of the function (2017-07-17):

exports.makeUppercase = functions.database.ref('/2017-07-17/messages/{pushId}/original')
        .onWrite(event => {

But this date should not be coded statically. Instead, it should be the current date.

I am not sure if something like this can be done. The idea would be to use curly braces like the {pushId}, but somehow reference the date field:

exports.makeUppercase = functions.database.ref('/{currentDate}/messages/{pushId}/original')
        .onWrite(event => {

Thanks for your help.

Upvotes: 3

Views: 825

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

This is currently not possible. The location for a reference must be fully known at the time it's deployed. It can't change over time. To change the reference, you would have to deploy it again with the updated string.

If you want to wildcard it like you can with other parts of the path, that's fine. You'll just have to accept that the function will be called for all dates, and you'll have to check the date in your function to decide what you want to do with it.

Upvotes: 2

Related Questions