问题
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