如何在所有数据库实例而不是默认实例上触发 firebase 功能? [英] How to trigger firebase function on all database instances rather than default one?
问题描述
我有 50 个实时 Firebase 数据库实例,它们都是相同的.
I have 50 realtime firebase database instances which are all identical.
是否可以让我的所有 firebase 函数在所有实例上触发,而不仅仅是在默认实例上触发?
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...
推荐答案
没有办法自动将一个函数与所有数据库实例相关联.您必须在自己的代码中将其与每个相关联,尽管您当然可以简单地定义一个单独的函数体,并将它们与所有相关联:
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)
这篇关于如何在所有数据库实例而不是默认实例上触发 firebase 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!