【问题标题】:Get data having a maximum attribute from firebase in nodejs从nodejs中的firebase获取具有最大属性的数据
【发布时间】:2018-06-07 00:59:30
【问题描述】:

所以我在 nodejs 中使用 firebase,在我的每个特定表的文档中都有一个“数字”属性(在运行时生成的名称)。我想获取属性“数字”的最大值的数据。

这是我的示例数据:-

    -L1GIb7Vyn6Yhd5gghH0

    correct: blah

    number: 9

    question: A sample question

    wrong1:  blekh

    wrong2:  blahhh

我已经看到诸如“childAdded”之类的答案,但几乎都是徒劳的,我也不能使用 .endAt() 或 startAt(),因为我在任何时候都不知道“数字”的值。

到目前为止,我的示例代码是:-

queRef.child(req.session.quiztopicname+req.session.quiztopictype).
    orderByChild("number").endAt(9).once("value",function(snapshot){
console.log(snapshot.val());
});

【问题讨论】:

    标签: node.js firebase firebase-realtime-database


    【解决方案1】:

    在您的排序参考/查询上使用limitToLast(1) 以仅检索最大值。请记住,如果有多个具有相同最大值的孩子,您仍然只会得到其中一个。还有更多文档或排序和过滤here

    【讨论】:

      猜你喜欢
      • 2017-06-02
      • 2012-05-10
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 2018-03-17
      相关资源
      最近更新 更多