0

this is the first time Im working with a JSON database (Realtime Firebase DB in Android app) and Im having issues to convert common 2 field primary key SQL data to a JSON structure.

This is the table:

enter image description here

And these are the rows I have to store:

USUARIO;ID_TRX
aaa;444
bbb;444
bbb;555

Im converting those rows to:

{
"RL_USR_TRX": {
   "aaa": [
      {
         "ID_TRX": 444
      }
   ],
   "bbb": [
      {
         "ID_TRX": 444
      },
      {
         "ID_TRX": 555
      }
   ]
}
}

When I manually upload this file to Realtime DB, I see it like this, with an unique parent node per same USUARIO:

enter image description here

Then, I dont know how to read data USUARIO=bbb and ID_TRX=555, as I dont know the parent node of ID_TRX=555 which in this case is 1.

I know I have problems in this approach, I read official docs and much more but cant figure out right how should I think this. Any help please?

  • Have you solved the issue? – Alex Mamo Apr 04 '22 at 08:13
  • @AlexMamo no, I havent – Leonel Fusco Apr 13 '22 at 14:57
  • Is `RL_USR_TRX` a direct child of the root node? Are there any other nodes that can hold `aaa`, and `bbb`? Are you allowed to change the database schema? – Alex Mamo Apr 14 '22 at 05:51
  • @AlexMamo RL_USR_TRX is direct chile of root node. No, aaa and bbb are only children of RL_USR_TRX. Yes, Im allowed. – Leonel Fusco Apr 18 '22 at 20:43
  • So to be clear, you need to get the user where the name is `bbb`, in order to read the value of the `ID_TRX`, which is 555, right? – Alex Mamo Apr 19 '22 at 05:43
  • @AlexMamo I want to check if USUARIO = bbb and ID_TRX = 555 exists in database, but without knowing the parent node of ID_TRX = 555, which in this case is 1 :) – Leonel Fusco Apr 19 '22 at 20:16
  • Unfortunately, that is not possible. Please check the [duplicate](https://stackoverflow.com/questions/48340925/how-to-sort-firebase-records-by-two-fields-android) to see a workaround. – Alex Mamo Apr 20 '22 at 04:53

0 Answers0