Saving and/or Querying User Display Names in Firebase using caseInSensitive?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 18:27:43

问题


I'm moving my project over to Firebase from Swift. Firebase user's don't have usernames but I'm allowing them to save a display name which works more like a attribute than an actual object. How can I get users to query for other users/"friends" using case in sensitive text?


回答1:


You can easily accomplish this task. We don't know how your current data is structured but here's an example

users
  user_id_0
    dsplay_name: "Smokey"
    lower_case_name: "smokey"
  user_id_1
    display_name: "Bandit"
    lower_case_name: "bandit"

When you create a user in Firebase, create a node in the /users node with their uid as the node name, and then display_name and lower_case_name as children

When you write your data to the users node, just lower case the display name when you are writing to the lower_case_name child:

let lowerCaseString = displayNameString.lowercaseString
let userRef = the users uid

let userData = ["display_name": "Bandit", "lower_case_name": lowerCaseString]
userRef.setValue(userData)

Then you query on the lower_case_name child using a lower case string.

ref.queryOrderedByChild("lower_case_name").queryEqualToValue("bandit")
   .observeEventType(.ChildAdded, withBlock: { snapshot in
}


来源:https://stackoverflow.com/questions/35328161/saving-and-or-querying-user-display-names-in-firebase-using-caseinsensitive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!