Firebase Database with no result

Viewed 2244

I'm using Firebase Functions for my Alexa skill. This is working as expected, but my data in the database is special and sometime the query can't return any value.

My keys are from 0101 to 1231 (MMDD) and if I query after the highest key, I don't get any callback, because firebase hasn't any data.

How can I set the query, that I find in that case the first >= "0101"?

The currently call is

admin.database().ref("calendar/birthday")
.orderByKey().startAt(key).limitToFirst(1).once("child_added")
.then(function(snapshot) { ... })

My database structure

"calendar" : {
  "birthday" : {
      "0111" : {
        ... -> 1st person
      },
      ...
      "0710" : {
        ... -> xth person
      },
      ...
      "1109" : {
        ... -> last person
      }
  }
}

My Alexa skill should name the next birthday and it will only work until 09. November and after 01. January, because I don't know how to query the data. Or can I structure my data in a better way to find the next birthday?

1 Answers
Related