'react-native-firebase realtime database .ref doesn't work
I can't read or write into my database, so I was trying to figure out the problem.
When I run console.log(database().ref("/users/123"));
I get "null/users/123"
But when I try this with firestore console.log(firestore().doc("users/" + userId));
I get a long message {"_documentPath": {"_parts": ["users", "Gz7eG1y7qWX6Q9gijSPDlcLcZop1"]},
...
When I run console.log(database());
I get a long message {"_app": {"_automaticDataCollectionEnabled": true, "_deleteApp": [Function bound deleteApp],
...
From this I assume that my firebase setup is correct, there should be a problem with the ref function.
Could you guys help?
I use "@react-native-firebase/app": "^12.0.0", "@react-native-firebase/database": "^12.0.0", "@react-native-firebase/firestore": "^12.0.0", "react-native": "0.63.4",
Solution 1:[1]
I am also facing the same issue nothing execute try,catch,then and when I console its give me null and when I use onChildAdded it give me My data. after some search I found mistake it was my Database Url I am using database() but I created my database other than an 'us-central1' default database,
import database from '@react-native-firebase/database';
const reference = database().ref('/users/123');
//not work for me
import { firebase } from '@react-native-firebase/database';
const reference = firebase
.app()
.database('https://<databaseName>.<region>.firebasedatabase.app/') //my dbUrl
.ref('/users/123');
// it work
you can read on RNfirebase Docs for more detail. I hope it help someone else
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Zeeshan |