I have written a cloud function that deploys perfectly well on a schedule, but only for the default database. In our Firebase project, we have a default prod database and a named dev database, and I can’t figure out how to talk to the dev database. I am currently using v1, and I know you need to use v2, but I still can’t figure out how to change the database, and this version works for at least one database.
when I deploy this:
const functions = require("firebase-functions"); // v1
const admin = require("firebase-admin");
admin.initializeApp();
const dbProd = admin.firestore();
const dbDev = admin
.initializeApp(
{
credential: admin.credential.applicationDefault(),
databaseURL: "https://ourdatabase.firebaseio.com",
},
"dbDev"
)
.firestore();
and pass it through this function:
exports.updateDevStatusDaily = functions.pubsub
.schedule("every day 00:04")
.timeZone("America/Denver")
.onRun(async (context) => {
await scheduledUpdate(dbDev);
return null;
});
it executes the function perfectly, but only on the production database. How can i pass the dev database to my function? Im I using the wrong url?
Duncan Findlay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.