How to trigger firebase function on all database instances rather than default one?

喜欢而已 提交于 2021-01-29 08:28:50

问题


I have 50 realtime firebase database instances which are all identical.

Is it possible to get all my firebase functions to trigger on all instances, rather than just the default instance?

I know you can do this

exports.myWriteFunction = functions.database.instance('my-secondary-db').ref('path/to/data').onUpdate((snap, context) => { ... })

But I really want to run this function on every instance...


回答1:


There is no way to automatically associate a function with all database instances. You will have to associate it with each in your own code, although you can of course simply define a single function body that you associate all of them with:

const myfunc = (snap, context) => { ... }
exports.myWriteFunction1 = functions.database.instance('my-secondary-db').ref('path/to/data').onUpdate(myfunc)
exports.myWriteFunction2 = functions.database.instance('my-tertiary-db').ref('path/to/data').onUpdate(myfunc)


来源:https://stackoverflow.com/questions/53423799/how-to-trigger-firebase-function-on-all-database-instances-rather-than-default-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!