简体   繁体   English

{Firebase-javascript} 如何从实时数据库的两条路径中查询数据

[英]{Firebase-javascript} How to query data from two path of realtime database

I want to query data from two path reference.我想从两个路径引用中查询数据。 Here is my database structure这是我的数据库结构

在此处输入图像描述

The data that I want are sum_powder from date of 2-3 (reference are "History/Sum/2021/6/2" and "History/Sum/2021/6/3") and included data in one array but I try this code my data is null.我想要的数据是 2-3 日期的 sum_powder(参考是“History/Sum/2021/6/2”和“History/Sum/2021/6/3”)并将数据包含在一个数组中,但我试试这个编码我的数据是 null。 What should I do?我应该怎么办? Thank you for your help.谢谢您的帮助。

var path1 = firebase.database().ref().child("History/Sum/2021/6/2")
var path2 = firebase.database().ref().child("History/Sum/2021/6/3")

path1.on('child_added', snap => {
    path2.child(snap.val().timestamp).once('value', data => {
        console.log("join : ",data.val())
    })
})

Try running both the promises in a Promise.all() :尝试在Promise.all()中运行这两个承诺:

var path1 = firebase.database().ref().child("History/Sum/2021/6/1").once("value")
var path2 = firebase.database().ref().child("History/Sum/2021/6/2").once("value")

Promise.all([path1, path2]).then((response) => {
  const [path1Snap, path2Snap] = response

  //Logging the values
  console.log("Value of path 1", path1Snap.val())
  console.log("Value of path 2", path2Snap.val())
})

The response is an array of snapshots received from Firebase.响应是从 Firebase 收到的一组快照。

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

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