I have multiple Firebase databases, and I would like to create one admin which connects to all databases. To initialize the app I first require the Firebase-admin module and initialize the app. If I run this again with different credentials it will still only initialize the one app.
var admin = require("firebase-admin");
...
Object.keys(config).map(function (k, i){
var c = config[k];
var serviceAccount = require(c.credential);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
apiKey: c.apiKey,
authDomain: c.authDomain,
databaseURL: c.databaseURL,
storageBucket: c.storageBucket
}, c.name);
...
}
This does not work! Only one app is initialized even though there are two configurations.
However, when you want to access multiple projects from a single application, you'll need a distinct Firebase application object to reference each one individually. It's up to you to initialize these other instances.
Create multiple Realtime Database instancesIn the Firebase console, go to the Data tab in the Develop > Database section. Select Create new database from the menu in the Realtime Database section. Customize your Database reference and Security rules, then click Got it.
Yes, You can use the same firebase database in more than one android application as below: In the Project Overview section of Firebase Console add an android application. For adding this application first you need to give that package name. Download config file in JSON format.
Queries with limited sorting and filtering functionality can be performed with the firebase database. Cloud firestore assures automatic scaling and can handle 1 million concurrent connections and 10,000 writes/second.
// Initialize the default app
firebase.initializeApp(defaultAppConfig);
// Initialize another app with a different config
var otherApp = firebase.initializeApp(otherAppConfig, "other");
console.log(defaultApp.name); // "[DEFAULT]"
console.log(otherApp.name); // "other"
// Use the shorthand notation to retrieve the default app's services
var defaultAuth = firebase.auth();
var defaultDatabase = firebase.database();
// Use the otherApp variable to retrieve the other app's services
var otherAuth = otherApp.auth();
var otherDatabase = otherApp.database();
Check out the Initialize mutltiple apps docs of the Firebase Admin SDK setup guide for more details.
Figured it out...
var app = admin.initializeApp({... })
var db = admin.database(app);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With