0
{
  "lambeosaurus": {
    "height" : 2.1,
    "length" : 12.5,
    "weight": 5000
  },
  "stegosaurus": {
    "height" : 4,
    "length" : 9,
    "weight" : 2500
  }
  "pegosaurus": {
    "height" : 4,
    "length" : 9,
    "weight" : 1000
  }
}

I want to select stegosaurus and pegosaurus from my parent node. It is similar like in query where we provide comma separated values in the query. e.g select * from my_table where id in ('stegosaurus','pegosaurus');

I have read the documentation of firebase and no help. Any suggestion will be very helpfull.

  • Possible duplicated: [Query based on multiple where clauses in Firebase](https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase) – R. García Jul 30 '18 at 06:46
  • Did you check the answer?? – Peter Haddad Jul 31 '18 at 09:48
  • Yes. I have tried these solutions but nothing work. So I paginated the call and check that my values exist. We have to request again and again with a key in equalto param so this was also not suitable for me. There is no method provided by firebase in which we can do in the query as SQL because all the data in firebase is stored in JSON. – aqiltariq65 Jul 31 '18 at 11:12
  • @aqiltariq65 yes the solution that I gave you is the only solution – Peter Haddad Jul 31 '18 at 16:05

1 Answers1

0

You can only do the following:

var db = firebase.database();
var ref = db.ref("users");

ref.orderByKey().equalTo("pegosaurus").on("value", (snapshot) => {
  snapshot.forEach((childSnapshot)=> {
     let length = childSnapshot.val().length;
     let height=childSnapshot.val().height;
     let weight=childSnapshot.val().weight;
    });
}); 

Here you check if the key is equal to pegosaurus and then you loop and retrieve the children data.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134