Advanced Firebase query with filter in Swift

I just came from the school of relational databases, and working with JSON databases is not an easy task for new users. I have this structure for storing users:

{
  "users" : {
    "0CcKvNkOm5fVqL" : {
      "birthday" : 564688000,
      "country" : "US",
      "email" : "email@live.com",
      "firstName" : "John",
      "gender" : "male",
      "isOnline" : true,
      "lastLoginDate" : 1468166460486,
      "lastName" : "Paul",
      "learningLanguages" : [ {
        "language" : "fr_FR",
        "levelID" : 2
      } ],
      "profileImage" : "https://firebasestorage.googleapis.com/image.jpg",
      "providerID" : "Firebase",
      "registrationDate" : 1468168460486,
      "speakingLanguages" : [ {
        "language" : "es_ES",
        "levelID" : 7
      } ]
    }
  }
}

I suggest a search screen in my application where users can search for other users, and they can combine all of these filter options:

Example:

Get 10users starting from index 0who:

  • male
  • and from"US"
  • and speaks "da_DK" with levelID 2 or / and "fr_FR" withany level
  • and recognizes "de_DE" withlevel 1 **and/or**recognizes "ar_AR" withlevel 4`
  • and withage range between 18 and 24
  • and by isOnline and last login date .

SQL, , users_languages:

SELECT ...
FROM users AS u
JOIN users_languages AS l
  ON u.id = l.id
WHERE u.gender = "male" 
AND u.age BETWEEN 18 AND 24 // need claculation but let keep it simple
AND u.country = "US"
AND ((l.language = "de_DE" AND l.mode = "learning" AND l.level = 1) OR (l.language = "ar_AR" AND l.mode = "learning" AND l.level = 4))
....
ORDER BY isOnline, lastLoginDate DESC
LIMIT 0,10

:

  • Firebase
  • , ( )
+4
1

: Firebase.

, , , .

: , , ElasticSearch, . , . .

Cool: - . , / . , .

, , . , , . . . - . .

: - , . : , , ; gender_country_age

Firebase

users
  -Jyiai09jsi
    data: "male_US_40"
  -Jqkjisjida
    date: "male_US_27"
  -JyHYjlkall
    data: "male_US_30"

30 40

usersRef.queryOrderedByChild("data").queryStartingAtValue("male_US_30")
        .queryEndingAtValue("male_US_40").observeSingleEventOfType(
       .Value, withBlock: { snapshot in
    print(snapshot)
})

, , , . , , .

- : : ,

user_countries
   US
       -Jyiai09jsi: true
       -Jqkjisjida: true
       -JyHYjlkall: true
   UK
      etc etc

user_gender
   male
       -Jyiai09jsi: true
       -Jqkjisjida: true
       -JyHYjlkall: true
   female
       etc etc

user_speaks
   da_UK
      users
   fr_FR
      users

; , .. , node . ; "" - , .

SQL ftw! , , Firebase. , Firebase, SQL- Firebase. , SQL- , Firebase , ..

. , , , , . , , male_US_30_FR. ,

, .

+9

All Articles