docs: update database usage with switching database URL (#3431)

* docs: update database usage with switching database URL

I struggled a while with finding out how to switch the database URL for the [DEFAULT] firebase instance during runtime.
With version 5 it was very easy with simply passing the databaseURL to the database module.

The docs did not help unfortunately, so I tried a lot of ways which are documented in this ticket:
https://github.com/invertase/react-native-firebase/issues/3049

This PR shall help other people with the same situation too.

Furthermore, I hope to get valid feedback if the proposed implementation documented in this PR is actually correct.

* refactor: move section above firebase.json

* refactor: change section title

* refactor: remove title, fix typo

* refactor: fix typo

* refactor: feedback from review
This commit is contained in:
Lisa Oppermann
2020-04-10 14:37:06 +02:00
committed by GitHub
parent adfd0777db
commit ff8b1ce12b

View File

@@ -318,6 +318,37 @@ database and the new [`DataSnapshot`](/reference/database/datasnapshot) containi
It is important that you understand how to write rules in your firebase console to ensure that your data is secure.
Please follow the firebase Realtime Database documentation on [security](https://firebase.google.com/docs/database/security)
# Using a secondary database
If the default installed Firebase instance needs to address a different database within the same project, call the database method on the default app with passing the database URL.
For example:
```js
import { firebase } from '@react-native-firebase/database';
const database = firebase.app().database('https://path-to-database.firebaseio.com');
database.ref();
```
## Connect to a database of a secondary app
If you want to address a database from a different Firebase project, you will need to create a secondary app first
(Read more on creating a secondary app here: https://rnfirebase.io/app/usage).
For example:
```js
import database, { firebase } from '@react-native-firebase/database';
// create a secondary app
const secondaryApp = await firebase.initalizeApp(credentials, config);
// pass the secondary app instance to the database module
const secondaryDatabase = database(secondaryApp);
secondaryDatabase.ref();
```
# firebase.json
## Disabling persistence