[英]react-native-firebase realtime database .ref doesn't work
我無法讀取或寫入我的數據庫,所以我試圖找出問題所在。
當我運行console.log(database().ref("/users/123"));
我得到"null/users/123"
但是當我用 firestore console.log(firestore().doc("users/" + userId));
嘗試這個時我收到一條長消息{"_documentPath": {"_parts": ["users", "Gz7eG1y7qWX6Q9gijSPDlcLcZop1"]},
...
當我運行console.log(database());
我收到一條長消息{"_app": {"_automaticDataCollectionEnabled": true, "_deleteApp": [Function bound deleteApp],
...
由此我假設我的 firebase 設置是正確的,ref function 應該有問題。
你們能幫忙嗎?
我使用"@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",
我也面臨同樣的問題,沒有執行 try、catch、then,當我控制台時,它給我 null,當我使用 onChildAdded 時,它給我我的數據。 經過一番搜索后,我發現錯誤是我的數據庫 Url 我正在使用 database() 但我創建的數據庫不是“us-central1”默認數據庫,
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
你可以閱讀RNfirebase Docs了解更多細節。 我希望它能幫助別人
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.