hellogoodnight hellogoodnight - 5 months ago 18
Javascript Question

Listen to changes on childs with keys within specific range only?

I want to listen for changes on my

calendar
node, but only if they occur on a child that has a key between a specified interval.
My Firebase looks like this:

{
"calendar":{
"160622" : {
// data
},
"160623" : {
// data
},
"160624" : {
// data
},
"160625" : {
// data
},
"160626" : {
// data
},
"160627" : {
// data
},
...
},
// other data
}


I want to do something equivalent to this:

firebaseRef.child("calendar").child("160622" to "160624").on("value", function(snapshot){
// do stuff
});


Is it possible?

Answer

Have you tried using orderByKey() with startAt() and endAt()?

firebaseRef.child("calendar").orderByKey().startAt("160622").endAt(160624").on("value", function(snapshot){
   // do stuff
});