0

I am try to create ios application for hotel booking. All my data are stored in firebase. My hotel's name and location are stored in "HotelLocation" table.

{
"HotelLocation": {
    "H1": {
        "name": "Ghetu hotel",
        "location": "shonargao,dhaka"
    },
    "H2": {
        "name": "BB hotel",
        "location": "gulshan,dhaka"
    },
    "H3": {
        "name": "Shuvashish hotel",
        "location": "uttara,dhaka"
    },
    "H4": {
        "name": "Bodi hotel",
        "location": "uttara,dhaka"
    }
  }  
 }

This is my json format of table 'HotelLocation' but I am unable to retrieve data from this table for only 'uttara' i.e. if I search for uttara then I should get

  1. Shuvashish hotel

  2. Bodi hotel

I tried by using 'queryEqualToValue' but problem is that 'uttara,dhaka' because firebase is case sensitive. So ',dhaka' is creating problem.

Is there any way of using SQL Command "%LIKE%" in Firebase?

KhanShaheb
  • 714
  • 2
  • 11
  • 26
  • Firebase doesn't have wildcard text search operations. See http://stackoverflow.com/questions/22506531/how-to-perform-sql-like-operation-on-firebase, http://stackoverflow.com/questions/39058119/firebase-database-requests-and-queries-like-sql-where-in and http://stackoverflow.com/questions/31036903/how-can-i-achieve-this-many-to-many-relationship-in-firebase – Frank van Puffelen Nov 04 '16 at 20:26

1 Answers1

1

If you use queryStartingAt("uttara") and queryEndingAt("uttara") it will return the nodes you want.

You just can't do an exact search on a wildcard char.

There are a bunch of other ways to tackle this like...

Create a node for the location that references the hotels like this, then you can just read in that node and you have a list of the hotels:

uttara
   H3: true
   H4: true

Or another option is to create references to the locations - suppose the Shuvashish Hotel has locations in both uttara as well as shonargao. Deep query the Hotels node for locations/L1 = true would return H3

locations
   L1: "uttara"
   L2: "gulshan"
   L3: "shonargao"


Hotels
     H2
       "name:": "BB hotel"
       "locations"
          L2: true
    H3
       "name": "Shuvashish hotel",
       "locations"
          L1: true
          L3: true
Jay
  • 34,438
  • 18
  • 52
  • 81