gpt4 book ai didi

Swift Firebase 查询

转载 作者:行者123 更新时间:2023-11-28 06:11:33 26 4
gpt4 key购买 nike

我正在尝试根据他的电子邮件获取 uid。

我有这个:

let usersRef = Database.database().reference().child("users")

usersRef.queryOrdered(byChild: "email").queryStarting(atValue: email).queryEnding(atValue: email).observeSingleEvent(of: .value, with: { (snapshot) in
if let values = snapshot.value as? [String: Any]{
print(values)
}
})

我的数据库如下所示:

用户

|-$uid

|--email: "一些电子邮件"

快照不返回任何内容。

另外,调试器告诉我:

Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "email" at /users to your security rules for better performance

我想我是这样做的:

{
"rules": {
"users": {
".read": "auth != null",
"$uid": {
".write": "$uid === auth.uid",
".indexOn": ["email"]
}

但这也行不通。

最佳答案

您必须在执行查询的位置定义 Firebase 数据库索引。所以这比你目前拥有的级别高了一个级别:

{
"rules": {
"users": {
".indexOn": ["email"],
".read": "auth != null",
"$uid": {
".write": "$uid === auth.uid",
}
}
}
}

关于Swift Firebase 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46386462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com