Abe Miessler
Abe Miessler

Reputation: 85096

How to find all records where date is later than?

I have a firebase db like the one below:

enter image description here

and I'd like to select all events that come after a certain date. I've attempted to do this with the following code:

events := []data.EventData{}

if err := ref.Child("date").OrderByValue().StartAt(time.Now()).Get(c, events); err != nil {
    fmt.Println("Error selecing upcoming events")
    fmt.Println("Error:", err)
    response.Message = "Problem getting upcoming events"
    c.JSON(http.StatusInternalServerError, response)
    return
}

But it keeps throwing the error:

Index not defined, add ".indexOn": ".value", for path "/Event/date", to the rules

What does this mean and how do I go about selecting the records that I need? Am I on the right track and just need to resolve this error or should I be taking a different approach?

Upvotes: 1

Views: 195

Answers (1)

Pan Ke
Pan Ke

Reputation: 579

Firebase is asking you add an index to date to improve query performance. AFAIK, you are able to get data you need without adding any index. But it will be quite slow as your event data grow. check the link for reference: https://firebase.google.com/docs/database/security/indexing-data

Upvotes: 2

Related Questions