0

Is there any possible way to filter data in Realtime Database(on Firebase). I'd like to filter them via checkbox values that can be multiple checked.

There will be 4 different elements to search in db: Category(might be chosen 8), Range(might be chosen 12), Topic(might be chosen 4)

Data is passed through screens,

I know that data is stored as JSON on Firebase

The application is being written on Android and iOS

But the checkboxes might be not checked too. I mean that category can be empty, but for example range and topic will be chosen. If there will be chosen nothing, it should display all the data that's stored

Beeednarek
  • 21
  • 4
  • This is an interesting use-case, and while it's of course always possible that somebody postt the exact solution you need - chances of that drastically go up if you show what you've done already for each step needed to implement this use-case. For example, the Firebase documentation has a section on [how to order and filter data](https://firebase.google.com/docs/database/flutter/lists-of-data#sorting_and_filtering_data) in Flutter. If you search for the relevant API calls from there, you'll probably also find other code samples and relevant questions. – Frank van Puffelen Feb 22 '23 at 20:25
  • @FrankvanPuffelen, i tried to work with firebase doc, but the problem is that for example orderbychild() etc. can be used only once for query. – Beeednarek Feb 22 '23 at 20:30
  • That's correct? So the question is not so much about Flutter, but about how to match multiple values? --- https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase is useful for that. You'll typically want to combine the values in a single property in the database, and then compare to that. And yes, this leads to lots of data duplication - but it's the only way to implement this type of query. If that doesn't fit your needs, consider using another database that better supports your requirement. – Frank van Puffelen Feb 22 '23 at 20:32

1 Answers1

0

It sounds like you want to execute a query with a complex condition with multiple clauses and multiple values per clause, which is something that Firebase Realtime Database doesn't support.

Read this question for some options on filtering data by multiple values: Query based on multiple where clauses in Firebase

If your needs are beyond what that discusses, it might be better to consider a database that better suits your querying needs. Within Firebase that could lead you to Firestore, which has a more flexible query API. But even that is still limited, so also consider SQL alternatives outside of the databases within Firebase.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807