Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if entry exists in Firebase Realtime Databse (Python)

I am currently trying to retrieve login information from my Realtime DB in Firebase.img

As an example, I want to detect whether the provided username already exists in the db.

Here is a code snippet I’m attemping to work with.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ref.child("Users").order_by_child("Username").equal_to("Hello").get()

It does not however work, and instead displays this message:

firebase_admin.exceptions.InvalidArgumentError: Index not defined, add ".indexOn": "Username", for path "/Users", to the rules

Is there something wrong with my code snippet or should I use a different alternative?

>Solution :

As the error suggests, you need to add ".indexOn": "Username" in your security rules as shown below:

{
  "rules": { 
    "Users": {
      ".indexOn": "Username",
      // ... rules
      "$uid": {
        // ... rules
      }
    }
  } 
}

Checkout the documentation for more information.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading