简体   繁体   English

Firebase:startAt() 未过滤以自纪元以来的小时数存储的数据

[英]Firebase: startAt() is not filtering data stored with keys as hours since epoch

My data is stored with keys as hours since epoch.我的数据从纪元开始以小时为单位存储在密钥中。 I want to get only slice of the data - so for example I want to specify that I want all data starting at 453615 .我只想获取数据的一部分 - 例如,我想指定我希望所有数据都从453615开始。

So far I got this code:到目前为止,我得到了这段代码:

  this.dbService.databaseRef.child('dev_trends/' + this.deviceUid)
  .orderByKey()
  .startAt('453615')
  .get().then(dataTrends => {
    const data = dataTrends.val();

    console.log(data);
  });

With the code above I get this results in my console:使用上面的代码,我在我的控制台中得到了这个结果:

在此处输入图像描述

My data model looks like this:我的数据 model 如下所示:

在此处输入图像描述

What should I change in my code so that I get the data from Firebase filtered?我应该在我的代码中更改什么以便从 Firebase 过滤数据?


I create the databaseRef variable inside a service with this code:我使用以下代码在服务中创建 databaseRef 变量:

  constructor(private db: AngularFireDatabase) {
    //Set what happens when we read all devices
    this.databaseRef = db.database.ref(); //Create databaseReference
  }

Json of my data:我的数据 Json:

  {"dev_trends" : {
    "-MkMxxZXXzmKclgeGPde" : {
      "H" : {
        "453614" : "50;45",
        "453615" : "50;50",
        "453617" : "50;55",
        "453630" : "51;60"
      },
      "T" : {
        "453614" : "24;18",
        "453615" : "23;17",
        "453617" : "23;15",
        "453630" : "22;10"
      }
    }
  }}

Find out where the problem was:找出问题出在哪里:

  • The startAt() method was filtering data with keys H and T and not the lists of data inside those keys. startAt()方法使用键HT过滤数据,而不是这些键中的数据列表。
  • Solution was to restructure the data model.解决方案是重组数据 model。

New data model:新数据 model:

在此处输入图像描述


Additional info:附加信息:

  • I am not saying my solution is ideal - but for my specific problem it will do the trick.我并不是说我的解决方案是理想的 - 但对于我的具体问题,它可以解决问题。
  • It will still require some additional work for me - so if anyone else has a better solution for this please post Your answer too:)它仍然需要我做一些额外的工作 - 所以如果其他人对此有更好的解决方案,请也发布你的答案:)

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

相关问题 在 Google Data Studio 中将纪元时间格式化为小时分钟 - Formatting Epoch time as Hours Minutes in Google Data Studio QML Firebase startAt 返回未定义 - QML Firebase startAt returns undefined 在 Flutter 应用程序上过滤和排序 Firebase (Firestore) 数据 - Filtering & Sorting Firebase (Firestore) Data on a Flutter App Firebase StartAt() 不起作用 - 没有它它返回相同的结果 - Firebase StartAt() doesn't work - it returns the same results without it Firebase 实时数据库监听 n 小时后添加的数据? - Firebase Realtime Database listen to data added n hours from now? 过滤来自Firebase的内容 - Filtering content from Firebase Objectify - 我们可以为 QueryKeys 设置 startAt(cursor) 吗? 或者如何迭代许多 Keys 查询? - Objectify - can we set a startAt(cursor) for QueryKeys? Or how to iterate over many Keys query? 访问存储在 firebase 实时数据库中的数据 - accessing data which is stored inside firebase real time database 反应:在 json 中找不到 firebase 存储数据用作 object - React: Can't find firebase stored data to use as object in json Firebase RTDB:游标的第二个参数(startAt,endAt ...)究竟是如何工作的? - Firebase RTDB: How exactly the 2nd argument of cursors(startAt, endAt...) work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM