1

How can i change database url (firebase real time db) in code? I would like to have option to choose which database you want (just different links)

I have firebaseConfig.ts file where is my firebaseconfig variable that contains apikey, authDomain, databaseURL, ...

2
  • If you have that config, you can change the databaseURL property in there to point to the database you want. Did it not work when you tried that? If so, can you show what you did and what error you got? Commented Dec 28, 2022 at 17:24
  • It worked that way, but i want to be able to change db e.g. based on button clicked. Answer below helped me and thank you for help :) Commented Dec 29, 2022 at 10:14

1 Answer 1

1

https://firebase.google.com/docs/projects/multiprojects#web

You can have multiple firebase configs in an object like

var configs = {"option1":{},"option2":{}}

and then initialise them all with different names like

var databases = {}
Object.keys(configs).map((name)=>{
  const app = firebase.initializeApp(configs[name],name);
  databases[name]=app;
})

then based on the choice you can access the database and access the db and change the values etc

const app = databases["option1"]
//access the realtime db and so on
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.