I have a an array of ids which are generated using the firebase.ref().push() method. For example -
myarray =
[-KoDeiUiqsMKDuXuwhzi,
-KoDrz6ngJtNrr51tguD,
-KoDyC-_ZeSIAN1_oFk4]
I have a node of items some of which match these ids -
/mynode
--KoDeiUiqsMKDuXuwhzi
-itemprop1 : "abc"
-itemprop2 : "xyz"
-id : "KoDeiUiqsMKDuXuwhzi"
--KnurYH554YNW6bcWch5
-itemprop1 : "opq"
-itemprop2 : "zyc"
-id : "KnurYH554YNW6bcWch5"
--KoDrz6ngJtNrr51tguD
-itemprop1 : "mon"
-itemprop2 : "ooo"
-id : "KoDrz6ngJtNrr51tguD"
..
..
..
..
..and so on.. basically the array of id's is a subset of this node. I want to retreive a all objects from this node where the id matches in the array. Currently the way i am doing is like this -
firebase.database().ref("mynode").once('value').then(function(snap){
snap.forEach(function(childsnap){
if(myarray.indexOf(childsnap.key) != -1){
//add to result
}
})
})
Although this code works but i think i can use orderByChild, startAt and endAt filtering to get the list of objects. Is there a way to get the result by filtering instead of getting all data and then filtering out? Will it be more efficient than this code?