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.


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?

Asked By: cybaltm



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.

Answered By: Dharmaraj