Firebase Realtime Database : Filter with REST API doesn’t work

Firebase,ServicesFirebase,REST API

Complex filter “orderBy" and “equalTo" doesn’t work

For example, if you send query with the simple REST API like ,

https://xxxxxxxx.firebaseio.com/users.json?orderBy="userID"&qualTo="ABCDEFGHIJK3LLMNOPQRS"

You may encounter the following Errors;

Error Message 1.

constraint index field must be a json primitive

Error Message 2.

"error" : "Index not defined, add \".indexOn\": \"email\", for path \"/users\", to the rules"

Solution

IndexOn rule is required.

According to the Firebase web document, add Indexing to your Firebase Realtime Database Rules: If you’re using orderBy in your app, you need to define the keys you will be indexing on via the .indexOn rule in your Firebase Realtime Database Rules.