1

I would like to query a real time Firebase database to find a document according to its source These are the fields that the document has:

class Document(BaseModel):
    _id: str
    series: str
    Country: str
    Date: str
    source: str 

For which I have defined the following function:

def get_source(self,
                   path: str,
                   source: str,
                   ):
        '''Method responsible only for filtering by document source'
        (like google, youtube, etc.)'''
        return self.db.reference(path)\
            .order_by_child("source")\
            .equal_to(source).get()

Subsequently, I build the endpoint that uses this function:

@router.get("/{source}")
def get_by_source(
    source: str,
    #only_id: Optional[bool]=False
    ):
    try:
        return fb_client.get_source(settings.FB_PATH, source)
    except Exception as e:
        return {"error": str(e)}

However when I test the endpoint I get this error:

{
"error": "Index not defined, add ".indexOn": "source", for path "/news", to the rules"
}

What does this mean? I am very new to Firebase

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Diego L
  • 185
  • 1
  • 9

0 Answers0