0

I created a project and built an app with that same name to work with a RTDB data base. Without knowing better I created another project for another app. But I want the second app in the second project to share the RTDB in the first project. It looks like I should have created the second app in the first project. How can I get both apps together to share the data base?

MartinDuo
  • 663
  • 12
  • 25
  • It sounds like you're unwilling to delete the app out of the second project and add it to the first project where it belongs? – Doug Stevenson Jun 24 '19 at 20:46
  • As Doug implies: the best way forward is to delete the second app from its current project, and recreate it under the other project. If that's not an option for you, please edit your question to explain why, and show the code of how you initialize Firebase in the second app. – Frank van Puffelen Jun 24 '19 at 21:54
  • I would do that. I can delete the whole second project, but I don't see an option to delete. Do I have to ask for the app's name again? I assume I would just add the app to the first project and set up hosting again. – MartinDuo Jun 24 '19 at 21:54

2 Answers2

0

As per the documentation you can use a different app to access multiple realtime databases.

For example with the JavaScript API: https://firebase.google.com/docs/reference/js/firebase.database.html

// Get the Database service for the default app
var defaultDatabase = firebase.database();

// Get the Database service for a specific app
var otherDatabase = firebase.database(app);

Note when creating app you can specify which configuration (database to load):

var firebaseConfig = {
  apiKey: 'xxxx',
  authDomain: 'xxxx',
  databaseURL: 'https://xxx.firebaseio.com',
  projectId: 'xxx'
};
var app = firebase.initializeApp(firebaseConfig);

For non-JavaScript consider referring to the following:

Regardless of language consider checking the API and selecting the language of your choice etc: https://firebase.google.com/docs/reference

Dean Taylor
  • 40,514
  • 3
  • 31
  • 50
0

Using information from both answers, I have gotten 80% of the way to a solution. First, as a newcomer to Firebase I created a project there using the name of my existing web app that was hosted on Azure, so it could use the Firebase RTDB. Then later I hosted the web app there using that same name. I thought the project and the app were the same thing. So when I built a second app I did the same and created a project with the app name and hosted the app there. Then I had a problem when I wanted the 2nd app to read from the RTDB used by the 1st app. Looking through the documentation as suggested by Dean I tried "var otherDatabase=firebase.database(app)", but had to guess just what "app" was. I tried several guesses, none of which worked, as it seems that approach is for different apps in a common project. And I learned that neither of my projects even had an app! So then using the approach suggested by Doug and Frank, I finally found the Delete button for projects. So I deleted the 2nd project, added my two web apps as apps to the first project, got the new Firebase configuration for the second app and finally that app can access the RTDB. The "firebase deploy" command works as before for the 1st app, but does not work for the 2nd app. Still working on that problem.

MartinDuo
  • 663
  • 12
  • 25