Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter complex object in Firebase?

Could you please help to filter below JSON using eventId?

{
  "-Kb2dYPV0yUXpD_1moc9": {
    "eventId": 1,
    "message": "sdfsdfsf",
    "sentOn": 1485004202943
  },
  "-Kb2etFm1xHd8sSsESeK": {
    "eventId": 1,
    "message": "shdfhsf",
    "sentOn": 1485004553847
  },
  "-Kb2etKON8nWVKS2R0sj": {
    "eventId": 2,
    "message": "shdfhsf",
    "sentOn": 1485004553853
  }
}

I'm using below URL,

https://xxxxxxxx.firebaseio.com/chats.json?orderBy="eventId"&equalTo=1

but getting constraint index field must be a json primitive error.

I want to retrieve chat objects with respect to particular event ID. I referred to the REST API, there, it was explained with simple JSON.

Please help me.

like image 270
Nagaraj N Avatar asked Dec 06 '22 15:12

Nagaraj N


1 Answers

I've run into the same error before using the firebase REST api, and it was because I didn't have quotes around the value in the equalTo clause (e.g. equalTo="1")

like image 123
Heath Avatar answered Jan 14 '23 02:01

Heath