简体   繁体   English

Firebase数据库参考快照不返回任何数据

[英]Firebase Database reference snapshot is not returning any data

I am trying to read some dummy data I have put into my Firebase database but cannot get it to return anything despite trying my best with following the documentation. 我正在尝试读取一些已放入Firebase数据库中的伪数据,但是尽管尽最大努力按照文档进行操作,也无法使它返回任何内容。

I have a JS file with Firebase initialized, and with this variable exported: 我有一个初始化了Firebase的JS文件,并导出了此变量:

const database = firebase.database();

In a file I'm trying to read it in, I have the below: 在我要读取的文件中,具有以下内容:

import database from './firebase';
const dbRef = database.ref('users/');
dbRef.on('value', (snapshot) => {
  console.log(snapshot.val());
});

Nothing gets logged out into the console. 什么都不会注销到控制台。 But when I log out just dbRef, I get the Reference object so it does seem to be connected properly: 但是当我仅注销dbRef时,我得到了Reference对象,因此它似乎确实已正确连接:

Reference {repo: Repo, path: Path, queryParams_: QueryParams, orderByCalled_: false}
database: (...)
key: (...)
orderByCalled_: false
parent: (...)
path: Path {pieces_: Array(1), pieceNum_: 0}
queryParams_: QueryParams {limitSet_: false, startSet_: false, startNameSet_: false, endSet_: false, endNameSet_: false, …}
ref: (...)
repo: Repo {repoInfo_: RepoInfo, app: FirebaseAppImpl, dataUpdateCount: 0, statsListener_: null, eventQueue_: EventQueue, …}
root: (...)
__proto__: Query

I can't find where I've went wrong, would really appreciate the help. 我找不到错误的地方,非常感谢您的帮助。 In my Firebase console, I am using Cloud Firestore by default rather than Realtime Database, not sure if that's making a difference. 在我的Firebase控制台中,默认情况下,我使用的是Cloud Firestore,而不是实时数据库,因此不确定是否有所作为。

You're trying to use the Realtime Database API instead of the Firestore API. 您正在尝试使用Realtime Database API而不是Firestore API。 They are not at all the same database, and they don't share the same API. 它们根本不是同一个数据库,并且它们不共享相同的API。 Use the Firestore docs to get started . 使用Firestore文档开始使用 You will use firebase.firestore() instead of firebase.database() . 您将使用firebase.firestore()代替firebase.database() The API docs for Firestore start here . Firestore的API文档从此处开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM