How can i search in firebase by different fields?

It is possible, but you would need to structure your data differently. You would need another "node" that listed each compatible item and its PN item as a sub-node e.g

recambios
  123ABC
    Compatible: ["ABC123","ABD123","ABE123"]
    Description: "3TB HDD"
    PN: "123ABC"

compatibles
  ABC123
   PN:"123ABC"
   Description: "3TB HDD"
  ABD123
   PN:"123ABC"
   Description: "3TB HDD"
  ABE123
   PN:"123ABC"
   Description: "3TB HDD"

In this way you can query the recambios table for descriptions, and compatibles for...compatibles

It does appear heavy handed and a duplication. Firebase call this de-normalising, and generally recommend this approach to make it possible to access and query subsets of data.

It would not take much to create this second structure when new records are added.

The fun would start when you have more than one part number that is compatible with a compatible!!

1 Like