使用caseInSensitive在Firebase中保存和/或查询用户显示名称? [英] Saving and/or Querying User Display Names in Firebase using caseInSensitive?
问题描述
我要将我的项目从Swift移到Firebase。 Firebase用户没有用户名,但我允许他们保存显示名称,该显示名称的作用更像是属性而不是实际对象。我该如何使用户使用敏感文本中的大小写来查询其他用户/朋友?
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?
推荐答案
您可以轻松地完成此操作任务。我们不知道您当前数据的结构,但这是一个示例
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"
在Firebase中创建用户时,请在/ users节点中创建一个节点,其uid为节点名称,然后将display_name和lower_case_name用作子节点
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
当您将数据写入用户节点时,在写入lower_case_name子级时,将显示名称小写:
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
}
这篇关于使用caseInSensitive在Firebase中保存和/或查询用户显示名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!