firebase - 为嵌套数据添加 .indexOn

标签 firebase

我收到 Firebase 警告“使用未指定的索引。请考虑在/user/544dceb6-98d-4f7e/clients 添加 ".indexOn": "E-mail"。

我添加的规则是:

{
  "rules": {
    "user": {
      "$clients": {
        ".indexOn": ["E-mail"]
      }
    }
  }
}

这是我正在调用的电话:

firebaseRef.child(authData.uid + "/clients").orderByChild("E-mail").equalTo(this.props.params.clientId).on('value', function(clientSnapshot) { ... }

这就是我的数据的结构:

database
+ user
  + 544dceb6-98d-4f7e...
      + clients
          + -K96sXIXRUIOK8....
              + E-mail

我怀疑这个问题与两层 key 有关,但找不到解决方案。

非常感谢!

最佳答案

您的rules.json中缺少一个级别:

{
  "rules": {
    "user": {
      "$userid": {
        "clients": {
          ".indexOn": ["E-mail"]
        }
      }
    }
  }
}

旁注:树中的user(单数)和clients(复数)有点令人困惑。使它们保持一致有助于使数据结构更易于理解。

关于firebase - 为嵌套数据添加 .indexOn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35145347/

相关文章:

java - 无法在 RecyclerView 中从 Firebase 获取数据

android - Firebase 远程配置 isDeveloperModeEnabled() 已弃用

android - 如何将文档快照(复杂对象)保存到共享首选项或文件?

java - 如何从java中的firebase中获取childs的Child值

firebase - 如何在 Go 中验证 App Engine 上的 Firebase ID token

firebase - 如何在 Firebase 查询中使用 startAt()?

javascript - Firebase V9 addDoc 未返回成功或失败或写入数据库

java - 安装应用程序后立即发送 FCM 注册

ios - 在Xcode 8.2上构建0字节文件会导致警告 "Mach-O: Reached end of file while looking for: uint32_t."吗?

swift - Firestore - 使用 querySnaphot 中的 Int 值一次创建多个文档