6

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.

AL.
  • 36,815
  • 10
  • 142
  • 281
Nagaraj N
  • 457
  • 6
  • 13
  • Works for me: https://stackoverflow.firebaseio.com/41789515.json?orderBy=%22eventId%22&equalTo=1&print=pretty – Frank van Puffelen Jan 22 '17 at 14:27
  • Frank, could you please explain me how you achieved it and what I'm doing wrong.. – Nagaraj N Jan 25 '17 at 00:43
  • I can't see what you're doing differently, hence showing you that it works. If you're still having problems, share a similar URL that fails and I'll have a look. – Frank van Puffelen Jan 25 '17 at 06:18
  • 1
    Thank you so much, for long days I was facing this issue, finally it got resolved by placing ".indexOn" rule at correct place/path. :) – Nagaraj N Jan 25 '17 at 07:26
  • Hmm.... that should've given you a very explicit error message that there wasn't an index for `eventId`. Sorry if the error message wasn't clear. But good to hear you got it sorted! – Frank van Puffelen Jan 25 '17 at 07:55
  • Hi Puf, Inside Service, couldn't listen for ValueEventListener, When activity exits, no toast is displayed from onDataChange() method. similar problem in http://stackoverflow.com/questions/38411098/firebase-keep-listening-to-childeventlistener-though-app-exits. I tried answer provided in this link, but didnt work. is there anyother way to achieve this ? – Nagaraj N Mar 06 '17 at 02:54

1 Answers1

16

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

Heath
  • 185
  • 1
  • 9