Home > Software engineering >  Check if entry exists in Firebase Realtime Databse (Python)
Check if entry exists in Firebase Realtime Databse (Python)

Time:09-18

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.

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?

CodePudding user response:

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.

  • Related