Running 2 firebase databases in the same ionic project


I need to add an other database to my existing one in my ionic 3 project. I’m using angularfire 2. I have an envirement.ts an other envirement2.ts.
these files contains 2 different firebase configuration (API key, authDomain …) .

this is a part of my app.module.ts :

import { AngularFireModule } from ‘angularfire2’;
import { firebaseConfig } from ‘…/environment’;
import { AngularFireDatabaseModule } from ‘angularfire2/database’;

declarations: [
imports: [

That’s why I am trying to add my firebase database as a provider instead of inside my component app.module.ts.
since I can only put one single config in app.module.ts :slight_smile:

export class FireProvider {
constructor( public db: AngularFireDatabase) {


How can 2 configurations files be initiated in the same app ?


Hi, I am stuck with the same. Can someone shed some light here?


I’ve never done it, but the idea is that you create two different Firebase projects, and create a database inside each project. Then you sign into both projects. There’s probably documentation on this, because it’s a recommended way to keep # of connections down. For example, you create two copies of your database, and flip a coin when your user wants some informtion, and on heads read from database 1, or tails read from database 2. So I’d suggest you dig around the advanced Firebase docs.

Edit: I got curious and looked for it myself. You want “web”


Thanks for the info. I have looked at this before asking here. Implementation is harder than the imagination :wink:


Maybe post code then, along with the error message you’re getting. It looks straightforward to me.


Page1 and Page2 with two different configs :
in .module.ts

Page1 calls an AuthService provider to createUserWithEmailAndPassword(email, password).
Page2 calls ProfileService provider to saveProfile(uid, firstname).

But the saveProfile method is always saving to database that the AuthService authenticated for.
How to create another instance of AngularFireModule - authenticate to that - and therefore save data to that project?

Not getting any errors - just not able to save to different databases. Data is saved to whichever project the AngularFireAuth instance is authenticated for.


That isn’t consistent with the docs, and it isn’t the question you first asked. To follow the docs I linked, you don’t use AngularFire. You create a database provider and then have two variables:

let primaryDatabase = primaryConfig.database()
let secondaryDatabase = secondaryConfig.database()

So those exist inside the database provider, you don’t need to do anything in app.module.ts.

Edit to add: If you want two instances of AF you could always create two providers, and import one instance of AF into each provider.


I already submitted an issue on github