0

I have a real-time database and one of its collections looks something like this:

"VisitorRecords" : {
    "1558098355174" : {
      "CardReturnApprovedBy" : "IXWjlt15qJPkjNDbl4PqG1cT13",
      "CreatedBy" : "IXWjlt15qJPkjNDblqG1cc0T13",
      "DatetimeCreated" : "Fri, 17 May 2019 13:05:55 GMT",
      "Status": 1
    },
    "1558445445664" : {
      "CardReturnApprovedBy" : "",
      "CreatedBy" : "IXWjlt15qJPkjNl4PqG1cc0T13",
      "DatetimeCreated" : "Tue, 21 May 2019 13:30:45 GMT",
      "Status": 1
    }
  }

My idea here is to filter all of the visitor records which have their DatetimeCreated bigger or equal to DateTime.Now (UTC) and then I want to update the Status property to 2. I want to do that from a firebase function.

What I've found so far is startAt(), endAt() helper functions but they don't seem to work in my case. Other option is to iterate all of the records and do a manual check for the date. Then, try to update this specific record using .update

I was wondering if there's no more simple and elegant way of doing this.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user2128702
  • 2,059
  • 2
  • 29
  • 74
  • 1
    What is not exactly working about startAt() and endAt() ? can you post what you have tried ? – Gastón Saillén May 21 '19 at 15:17
  • @GastónSaillén For example, if I want them to startAt UTC.now but I have no record equal to UTC now. – user2128702 May 21 '19 at 15:21
  • With the format of your DatetimeCreated values you will have a lot of problems to sort them correctly. You should better use a timestamp, see https://firebase.google.com/docs/reference/js/firebase.database.ServerValue – Renaud Tarnec May 21 '19 at 15:32
  • See https://stackoverflow.com/questions/52728669/querying-by-range-in-firebase/52732340#52732340, https://stackoverflow.com/questions/38216858/firebase-query-by-date-string/38226376#38226376 and https://stackoverflow.com/questions/52921518/why-doesnt-the-firebase-query-look-like-list/52931580#52931580 – Frank van Puffelen May 21 '19 at 22:06
  • @FrankvanPuffelen So, as I understand, your suggestion is the same as the one suggested by 'RenaudTarnec' to have my date represented as a timestamp and then use startAt with a value of utc.now converted to a timestamp number? – user2128702 May 22 '19 at 08:58

0 Answers0