不要检索记录的孩子

时间:2017-08-03 16:27:28

标签: javascript firebase firebase-realtime-database

请假设以下结构:

/parentNode
     / ...
     /childNode <-- I only want this KEY without retrieving childChildNodes
         /childChildNode
         /childChildNode
         /...andManyManyMoreChildChildNodes...
     /childNode <-- by limitToFirst(2) I maybe also want this KEY but again without retrieving all the rest
         /childChildNode
         /childChildNode
         /...andManyManyMoreChildChildNodes...
     /...andManyManyMoreChildNodes...
         / ...

我来到这样的事情:

let child = "1500127452209";
const findDateRef = firebase.database().ref("parent/");
findDateRef.orderByKey().startAt(child).limitToFirst(2).once('value', snap => {
    console.log("result I want", Object.keys(snap.val()));
    console.log("data retrieved", snap.val());
});

第一个日志代表我想要的结果,但是第二个日志显示在客户端上检索并过滤了所有不需要的数据,这不是我想要的。

那么如何阻止Firebase读取子节点?

1 个答案:

答案 0 :(得分:1)

实时数据库的结构是从引用读取读取该引用下的所有数据,包括子节点。如果您只需要数据的某些部分,那么除了这里的数据外,该数据应该有自己的节点。在中,您需要对数据进行非规范化。以下是一些资源:

Documentation- Best practices on structuring the Firebase Realtime Database

Denormalization is normal with the Firebase Database - Firecasts

The Firebase Blog: Denormalizing Your Data is Normal

相关问题