如何通过孩子的属性查询Firebase?

Vin*_*rad 5 angularjs firebase ionic-framework firebase-realtime-database

架构:

架构:

我正在尝试按所有者过滤所有对象

为了获得具体的信息,我这样做:

var refCompaniesById = firebase.database().ref('companies').child(id);
Run Code Online (Sandbox Code Playgroud)

但在这种情况下我想过滤所有

我试过:

ref.child('companies').child().set({"owner": id})
Run Code Online (Sandbox Code Playgroud)

但我失败了。

adr*_*727 5

firebase.database().ref('companies').orderByChild('owner').equalTo(id)
  .once('value')
  .then(snapshot => {
    const records = snapshot.val();
    console.log(`Companies whose owner id is ${id}: `, records);
  })
  .catch(error => console.log(error));
Run Code Online (Sandbox Code Playgroud)