Reputation: 85096
I have a firebase db like the one below:
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
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