0

Is there any way to query a firebase child node and check if it contains a value.

At the moment my code is :

Query query=treasuresRef.orderByChild("category").equalTo(category);

However, this does not work for me, because sometimes I have multiple categories in a child separated by a comma. I want to query to check if the child category contains the substring variable category.

Any suggestions?

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • Please add your database structure to see you issue more clearly. – Alex Mamo Feb 07 '18 at 13:53
  • 1
    AFAIK this is not possible without using any third party service like Algolia or ElasticSearch. – simon Feb 07 '18 at 14:03
  • The Firebase Database can only do so-called prefix queries, which check whether a value *starts with* a certain string. There is no operator to check if a value *contains* a string. As simon says, you'll need to use a third-party search solution for that. Also see https://stackoverflow.com/questions/28589092/firebase-query-find-item-with-child-that-contains-string – Frank van Puffelen Feb 07 '18 at 15:16
  • Btw: I'd recommend against storing multiple categories in a single string. For a good idea on how to store categories, so that you can easily look up the items for a category have a look at my answer here: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Feb 07 '18 at 15:17

0 Answers0