[英]Check if entry exists in Firebase Realtime Databse (Python)
I am currently trying to retrieve login information from my Realtime DB in Firebase.我目前正在尝试从 Firebase 中的实时数据库中检索登录信息。
As an example, I want to detect whether the provided username already exists in the db.例如,我想检测提供的用户名是否已存在于数据库中。
Here is a code snippet I'm attemping to work with.这是我正在尝试使用的代码片段。
ref.child("Users").order_by_child("Username").equal_to("Hello").get()
It does not however work, and instead displays this message:但是它不起作用,而是显示以下消息:
firebase_admin.exceptions.InvalidArgumentError: Index not defined, add ".indexOn": "Username", for path "/Users", to the rules
Is there something wrong with my code snippet or should I use a different alternative?我的代码片段有问题还是应该使用其他替代方法?
As the error suggests, you need to add ".indexOn": "Username"
in your security rules as shown below:正如错误提示的那样,您需要在安全规则中添加
".indexOn": "Username"
,如下所示:
{
"rules": {
"Users": {
".indexOn": "Username",
// ... rules
"$uid": {
// ... rules
}
}
}
}
Checkout the documentation for more information.查看文档以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.