Home > OS >  Bypass random id in Firebase Realtime REST
Bypass random id in Firebase Realtime REST

Time:11-06

If my data structure looks like this:

documents.json:
{
  "-NG8qzvgs46A5gojZbJO": {
    "-NG8r-2q1-47MWK35aT2": {
      "description": "My Description",
      "title": "My Title"
    },
    "author": "jim",
    "date": "05/11/2022"
  },
  "-NG8ta4xpHGZxA4JRUQZ": {
    "-NG8ta9e90ChdMQclirn": {
      "description": "My Description",
      "title": "My Title tom"
    },
    "author": "tom",
    "date": "04/11/2022"
  },
  "-NG8tjfP_TYJHZcjouY8": {
    "-NG8tjiryoxnWbb4wwQQ": {
      "description": "My Description ccc",
      "title": "My Title jim"
    },
    "author": "jim",
    "date": "05/11/2022"
  }
}

How to get all the entries where author="jim"? This does not work:

https://testing-11f41-default-rtdb.firebaseio.com/documents.json?orderBy="author"&equalTo="jim"

Is it possible using Firebase REST API? Thanks in advance.

CodePudding user response:

When I access the URL you give, I get this response:

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

As this message says, you need to add an index to allow this query.

In your rules:

{
  "rules": {
    ...
    "documents": {
      ".indexOn": "author"
    }
  }
}
  • Related