【问题标题】:FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the clientFIREBASE 警告:使用未指定的索引。您的数据将在客户端下载和过滤
【发布时间】:2021-11-10 18:07:19
【问题描述】:

@firebase/database:FIREBASE 警告:使用未指定的索引。 您的数据将在客户端下载和过滤。考虑 在 /groups/test/leadPropertyInformations 添加 ".indexOn": "status" 符合您的安全规则以获得更好的性能。

Firebase RTD 规则

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",
      "groups": {
      ".indexOn": ["leadPropertyInformations/status"]
    }
  }
}

JSON 树

注意:您看不到status 属性。但它在第三个箭头路径上。

使用AngularFire查询

getActiveLeadPropertyInformations(): Observable<LeadPropertyInformationModel[]> {
    return this.angularFireDatabase
      .list<LeadPropertyInformationModel>(
        `groups/${this.groupId}/leadPropertyInformations`,
        (ref) => ref.orderByChild('status').equalTo('active')
      )
      .valueChanges()

      .pipe(first());
  }

你能告诉我我的规则有什么问题吗?

【问题讨论】:

    标签: angular typescript firebase firebase-realtime-database angularfire


    【解决方案1】:

    您的规则中需要更多占位符才能使 i 工作:

    {
      "rules": {
        ".read": "auth != null",
        ".write": "auth != null",
          "groups": {
              "$groupId": {
                 "leadPropertyInformations":{
                   
              ".indexOn": ["status"]
             
            }
           }
          }
      }
    }
    

    【讨论】:

    • 这也不行?任何线索为什么?上面同样的错误。
    • 用更新的版本试试。那个正好在错误消息的路径上。您还应该考虑索引不会立即发生。我会稍等片刻,具体取决于您在这些路径上有多少元素。
    • 当然,我会尝试并通知您。我只有 2 个节点,因为这是开发模式。
    • 这工作正常。非常感谢!
    【解决方案2】:

    路径不正确(至少不像问题中描述的那样)

    你的索引是

    leadPropertyInformations/status 
    

    而路径其实是

    leadPropertyInformations/22611/status
    

    注意路径中的 22611 - 这意味着您需要添加一些内容来表示子节点,例如 $an_id 以引用问题中显示的子节点。

    【讨论】:

    • 这根本不是一个解决方案,因为我需要一个通用的解决方案,因此我不知道预先收集的 id。
    • @Sampath 你的问题是 你能告诉我我的规则有什么问题吗? 例如您想知道您的规则的问题是什么,而这个解决方案就是解释问题的答案。如果您想知道如何编写通用规则,那么问题应该是这样的 - 如果您查看屏幕截图,则路径不是通用的,而是特定的。
    猜你喜欢
    • 2022-11-16
    • 2021-08-05
    • 2021-12-31
    • 2019-04-19
    • 2021-01-14
    • 2019-09-22
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多