Home > Net >  Query for a specific item in firebase from python
Query for a specific item in firebase from python

Time:08-30

I am getting this error Index not defined, add ".indexOn": "Number", for path "/public_access", to the rules and have no idea what the issue is. All I'd like to do is retrieve (Check if the entry exists in my db) to see if the tag has already been use

My rules look like this

{
  "rules": {
    "public_access": {
      "all_users": {
        ".indexOn": "Numbers"
      },
      ".read": "auth.uid === 'regular_user'",
      ".write": true,
    },
      
    "connection_testing": {
      ".read": true,
      ".write": "auth.uid === 'admin_user'"
    },
    "login_data": {
      ".read": true,
      ".write": true
    },
  }
}

And the python code I am trying to use is this

ref = db.reference('/public_access/all_users')
snapshot = ref.order_by_child('Number').equal_to('AAAAAA').get()

But it just errors, I've tried copying so many different examples and I've been stuck on it for hours. I know the solution will be something stupidly simple but I just can't apply it to what I want to do.

enter image description here

I don't need the number value at all, it was just an attempt to get it to find 'AAAAAA'. The end goal is to see if AAAAAA exists by searching for it, and I have not been successful at achieving this

CodePudding user response:

You don't need order_by_child or database rules here. If you want to search for "AAAAAA", just access it by the child method:

ref = db.reference('/public_access/all_users')
data = ref.child('AAAAAA').get()
print(data['Date_of_join'])    # '12/34/34'
print(data['Number'])          # 2
  • Related