我有一个具有以下结构的数据库
"users":{
"user1234" {
"username": "user1234"
}
}
我正在尝试查询用户名" user1234"的用户。当我使用queryEqual(toValue :)时,我没有得到任何匹配,但在使用queryStarting(atValue :)时,我确实得到了用户。我已确认用户名实际上是" user1234"。我做错了什么?
let query1 = databaseRef.child("users").queryOrdered(byChild:"username").queryStarting(atValue: "user1234").queryLimited(toFirst: 1)
query1.observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in
//snapshot contains the user with username "user1234"
})
但以下情况不起作用
let query2 = databaseRef.child("users").queryOrdered(byChild:"username").queryEqual(toValue: "user1234")
query2.observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in
//snapshot DOES NOT contain the user with username "user1234"
})
我的安全规则是
"rules": {
".read": "true",
".write": "true",
"users": {
"$uid": {
".indexOn": ["username"],
},
},
},