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

Query for a specific item in firebase from python

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

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 = 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

>Solution :

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
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