I have a firebase project up and running with a realtime database and cloud functions in javascript and everything is working well. I added another database instance to the project recently and I would like to be able to write data directly to that database, as well as the original database. Unfortunately I have only been able to write to the default/original database, no matter what I try.
Currently I can write to the first database (we’ll call it db1) using this method:
admin.database().ref().child("node_name_here").set("value_to_set")...
As you can see, I don’t need to specify the instance name, it just defaults to the original db1 database. I would like to be able to write to the second database instance within this same function too.
I did a lot of research but didn’t find anything that directly answered my question. I tried various solutions, such as passing in the instance name and also the instance link something like this.
admin.database().instance("db2").ref().child("node_name_here").set("value_to_set"){
And also something like this,
admin.database().instance("https:www.my_database_url.com/db2").ref().child("node_name_here").set("value_to_set")...
I have been able to listen to and write to the second database with database listener functions such as below,
exports.testFunction = functions.database.instance("db2").ref('/items/{pushId}').onCreate( (snapshot, context) => {
//Do something in here:
});
But i have not been able to write to the second database in my http functions that are triggered by http requests, not database listeners.
I’m very grateful of any help on this, as I feel like I’m getting a bit of tunnel vision and need some fresh eyes. Thanks.