我尝试在 Android 应用程序中执行 orderByChild
操作,但收到警告:使用未指定的索引。考虑将 users/4Gc9OgFWw5hwr2YFxbfwLgyAp1V2/posts 处的 '".indexOn": "timestamp"' 添加到您的安全和 Firebase 数据库规则
这就是我构建数据库的方式:
这是我尝试添加到数据库的规则:
{
"rules": {
".read": "auth != null",
".write": "auth != null",
"users": {
"uid": {
"posts": {
".indexOn": "timestamp"
}
}
}
}
}
但是,它仍然给我这个警告。我该如何修复它?我在某处看到您可以对 uid 子项使用任何变量,这就是为什么我在那里有 uid
变量,但我也尝试过不使用它。
最佳答案
规则中应该是 $uid
而不是 uid
结帐this
{
"rules":{
".read":"auth != null",
".write":"auth != null",
"users":{
"$uid":{
"posts":{
".indexOn":"timestamp"
}
}
}
}
}
关于android - 在时间戳 Firebase 上建立索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48311444/