4

I have a problem doing complex queries in Firestore database. I have read the documentation countless times so I know where the limitations are, but I wonder whether there is a way to structure the data so it supports my use cases. Let me explain what the use cases first:

I have a list of jobs, and users and I want to able to list/filter jobs according to some criteria and to list/filter users according to some criteria.

Job

JOB ID
 - job type (1 of predefined values)
 - salary (any number value)
 - location (any value)
   - long
   - lat
 - rating (1 - 5)
 - views (any number value)
 - timeAdded (any timestamp value)
 - etc.

User

User ID
 - experiences (0, 1 or more of predefined values)
   - experience1
     - jobCategory
     - jobName
     - timeEmployed
   - experience2
     - etc
 - languages (0, 1 or more of predefined values)
   - language1
     - languageName
     - proficency
   - language2
     - etc.
 - location (any value)
   - long
   - lat
 - rating (1 - 5)
 - views (any number value)
 - timeLastActive (any timestamp value)
 - etc.

Filtering by field which can only have one value is fine. Even when I add sorting by "timeAdded" or a ragne filter.

1) The problem is when I introduce second range filter, such as jobs with "salary" higher then 15 bucks and at the same time "rating" higher then 4. Is there a way to get around this problem when I have N range filters?

2) Second problem is that I cannot use logical OR. Lets say, filter jobs, where "jobCategory" is Bartender or Server.

3) Another problem is to filter by fields, which can have more then 1 value, e.g. User can speak more than one language. Then if I want to filter users which speak English, it is not possible. Not to mention to filter users who speak e.g. English OR French.

I know I can model the data the way that I use the language as the name of the field, like -english = true, but when I introduce range filter to this, I need to create a Firestore index, which is very inconvenient since I can have around 20 languages and around 50 job types at the same time, and I would have to create indexes all the combinations together with different range filters.. is this assumption correct?

4) How would I filter jobs which up to 20 km from certain position? Radius and the position is on the user to choose.

5) What if I want to filter by all those fields at the same time? E.g. filter certain "jobCategory", location and radius, "salary" higher then something and "rating" higher then something, and sort it all by "timeAdded".

Is this possible with Firestore / Realtime database, can I model the data in some way to support this, or do I have to look for an alternative DB solution? I really like the real-time aspect of it. It will come handy when it is time to implement chat feature to the app. Is it solvable with Cloud functions? I am trying to avoid doing multiple requests, merging them together and sending that to client, since there can be any combination of filters.

If not doable with Firebase, do you know of any alternatives similar to Firestore with better querying options? I really hope I am just missing something :)

Thank you!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
marstaj
  • 51
  • 4
  • Hello @marstaj, did you succeed to get a solution to your question? If yes, can you share here? – cdaiga Mar 12 '20 at 13:27
  • Hi @cdaiga. We have since then stopped using Firestore and moved to SQL database. Sorry that I don't have an answer for you. – marstaj Apr 09 '20 at 20:35

0 Answers0