You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enable connection to multiple database instances of the same project #1567
I would like to access multiple realtime databases within the same firebase app project.
As you can find in the documentation "Scale with Multiple Databases > Connect your app to multiple database instances":
// Get the default database instance for an app
var database = firebase.database();
// Get a secondary database instance by URL
var database = firebase.database('https://testapp-1234.firebaseio.com');
You should be able to do this with DI in the @next release using the RealtimeDatabaseURL injection token. I've been meaning to document this. Give it a shot.
Hi @jamesdaniels, I've been needing to change to different databases into the same project. You mentioned RealtimeDatabaseURL injection token on the @next release. Could you elaborate a little bit more on that? Is there any documentation? Sample? Specific files to glance at?
Reacted by Matt Wlodarski, FFSDevelopers, rafaveig, Akila Hewage, Mussa Charles, Catalin Ungureanu, Shiva-Kumar-Reddy, Luis Miguel Gamboa, Ahmed Abdelfattah Ahmed and imbradyboy
Reacted by JanOschii, Ananya Neogi, FFSDevelopers, Mussa Charles and imbradyboy
Reacted by FFSDevelopers, Mussa Charles and imbradyboy
@jamesdaniels I need to access data from both databases in the same component. How can I achieve that?
Hmm. Can the injection token be defined per @Injectable()? That way I could wrap all my database access to services and be done with it. Is it possible?
@swftvsn If @CarlosACabrera code is running, I wouldn't call it a workaround.
It is the way I would like to use angularfire with multiple databases. @jamesdaniels Do you see any problem with this implementation?
There's the RealtimeDatabaseURL injection token as of rc7. The individual modules no longer pull the angularfire app module directly, instead use the factory each time. So just provide it in your module declaration.
If you need multiple databases in the same component building the ref as @CarlosACabrera is the correct way to do this; you could also get fancy and make your own module for AngularFireDatabase to use both, but IMO not worth it unless you were referencing two separate Firebase applications in the same module.
Activity
jamesdaniels commentedon Apr 19, 2018
You should be able to do this with DI in the
@nextrelease using theRealtimeDatabaseURLinjection token. I've been meaning to document this. Give it a shot.fnhipster commentedon Apr 30, 2018
Hi @jamesdaniels, I've been needing to change to different databases into the same project. You mentioned
RealtimeDatabaseURLinjection token on the@nextrelease. Could you elaborate a little bit more on that? Is there any documentation? Sample? Specific files to glance at?Any help is highly appreciated.
fnhipster commentedon Apr 30, 2018
I found a workaround that works with current
@5.0.0-rc.6.0.swftvsn commentedon May 2, 2018
@jamesdaniels I need to access data from both databases in the same component. How can I achieve that?
Hmm. Can the injection token be defined per
@Injectable()? That way I could wrap all my database access to services and be done with it. Is it possible?JanOschii commentedon May 3, 2018
@swftvsn If @CarlosACabrera code is running, I wouldn't call it a workaround.
It is the way I would like to use angularfire with multiple databases.
@jamesdaniels Do you see any problem with this implementation?
swftvsn commentedon May 3, 2018
Yeah @JanOschii, I need to experiment more, I've tried to solve this earlier, for context see #1240
jamesdaniels commentedon May 4, 2018
There's the
RealtimeDatabaseURLinjection token as of rc7. The individual modules no longer pull the angularfire app module directly, instead use the factory each time. So just provide it in your module declaration.See here https://github.com/angular/angularfire2/blob/master/src/database/database.ts#L19
I'll work on docs for this.
If you need multiple databases in the same component building the ref as @CarlosACabrera is the correct way to do this; you could also get fancy and make your own module for AngularFireDatabase to use both, but IMO not worth it unless you were referencing two separate Firebase applications in the same module.
texano00 commentedon Jun 18, 2018
Hi @CarlosACabrera
I've tried your solution but the method
databaseseems to not accept any params.[ts] Expected 0 arguments, but got 1.
I've also tried to disable tslint but the param of
databasemethod is not considered.I've tried it with @5.0.0-rc.10 and @5.0.0-rc.6.0
florent1933 commentedon Jul 11, 2018
@texano00 , I have the same problem. Did you resolve this?
Does anyone had the same problem?
fnhipster commentedon Jul 11, 2018
@texano00, @florent1933
The solution works but it does throw that typing error.
You could fix it by adding
instance?: stringto/node_modules/firebase/index.d.tsline 122This is an issue with the
firebasenpm package. Please refer to this PR firebase/firebase-js-sdk#1001florent1933 commentedon Jul 11, 2018
Thanks for your answer @CarlosACabrera, it's very helpful.