大家好。我遇到了 firebase 数据库的问题。我想根据时间戳获取最后两个 processdata 对象。我不希望它在 processdata 的父对象中返回,因为要求是 rawdata 对象,它是父对象的另一个子对象,不应发送到应用程序端。因此,获取父对象也会获取原始数据,因为它也是子对象。我怎样才能避免它?正如我所说,以下代码在父对象中返回processdata
var firebaseHeadingRef6 = firebase.database().ref('pond2/temperature');
firebaseHeadingRef6.orderByChild("{key}/processdata/timestamp").limitToLast(2).on("value", function(snapshot) {
console.log(snapshot.val());
});
最佳答案
你不能。当您从 Firebase 加载任何数据时,其所有子数据都会随之而来。强调我的:
when you fetch data at a location in your database, you also retrieve all of its child nodes. In addition, when you grant someone read or write access at a node in your database, you also grant them access to all data under that node. Therefore, in practice, it's best to keep your data structure as flat as possible. https://firebase.google.com/docs/database/web/structure-data
将您的原始数据
与应发送给客户端的数据分开存储。
关于javascript - 没有子节点之一的 Firebase 数据检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44526070/