0

firebase

I have check pyrebase and i want to search for the IDNumber of each user.

i have tried using

db.child("Users").order_by_child("IDNumber").equal_to(2011445392).get()

But it gave me an error related to index not defined. Is there a way to search for IDNumber similar to SQL?

Ezz Redfox
  • 89
  • 1
  • 9
  • i can't do that because i will not know if 'Morty' will have the id number 2011445392 or someone else. so i would be using the id number for searching users instead of names. – Ezz Redfox Feb 01 '19 at 15:36
  • 1
    You are right, read [guide/indexing-data](https://www.firebase.com/docs/security/guide/indexing-data.html) – stovfl Feb 01 '19 at 15:52

1 Answers1

1

Your query is correct. The error about index not defined occurs because you haven't set any rule on IDNumber.

You need to configure rules on your indexes like this :

{
  "rules": {
    "Users": {
      ".indexOn": ["IDNumber"]
    }
  }
}

https://firebase.google.com/docs/database/security#section-defining-indexes

tscherrer
  • 48
  • 9