0

I'm creating an application where people can create a postering job with jobs in multiple cities. For example a job could contain posters in Toronto, Montreal & Chicago. I would like to organize it using a posters array like the following

{
  "posters": [
    {
      "id": "axf",
      "city": "Toronto"
    },
    {
      "id": "axf",
      "city": "Montreal"
    },
    {
      "id": "axf",
      "city": "Calgary"
    }
  ]
}

I would like to filter to find all of the jobs with posters in a certain city. Is this possible? I could also do it in a single string like the following

"posters":"Toronto&Montreal&Chicago"

Could I use something like Regex in the real-time database orderBy query? Here is the current query

    .orderByChild("job/job/city").equalTo("toronto")

I thought about something like this

 .orderByChild("job/job/city").equalTo(".*Toronto.*")

If this doesn't exist I'll make a feature request!

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
user1743524
  • 655
  • 1
  • 7
  • 14

1 Answers1

0

Firebase Realtime Database has limited querying capabilities, and nothing to the point of what you're trying to do. If you want a more elaborate query API while staying within Firebase, you may want to consider using Firestore instead.


If staying on the Realtime Database, you'll first want to reconsider your use of an array to store data, as Firebase actively recommends against arrays, e.g. in Best Practices: Arrays in Firebase.

To better be able to query data in categories on Realtime Database, consider changing your data model to the way I showed here: Firebase query if child of child contains a value

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807