【问题标题】:Firebase no index defined even when using .indexOn correctly?即使正确使用 .indexOn,Firebase 也没有定义索引?
【发布时间】:2020-02-22 23:39:33
【问题描述】:

我收到一条错误消息:

FIREBASE 警告:使用未指定的索引。您的数据将在客户端下载和过滤。考虑将 /questions 处的 ".indexOn": "author" 添加到您的安全规则中以获得更好的性能。

我的 Firebase 规则:

"questions": {
      ".read": true,
      ".write": true,
        ".indexOn": ["category,author"]
    },

我的 Firebase 数据:

 "questions" : {
    "-Ls1LfayKF9TUg20ByPE" : {
      "question" : "1",
      "timestamp" : 1571997530706,
      "author" : "9jNkvzr0chgPi0SC6rXMlVWdOF12"
    },
    "-Ls1Lj_OG4lo11r3WQzF" : {
      "question" : "2",
      "timestamp" : 1571997546988,
      "author" : "9jNkvzr0chgPi0SC6rXMlVWdOF12"
    },

我的代码:

const ref = FirebaseRef.child('questions')
ref.orderByChild('author').equalTo(UID).limitToLast(this.state.limit)
      .on("child_added", snapshot => {
       console.log("FireB ",snapshot)
    var items = [];
    snapshot.forEach((child) => {
      items.push({
        key: child.key,
        ...child.val()
      });
    });

【问题讨论】:

    标签: javascript firebase firebase-realtime-database firebase-security


    【解决方案1】:

    .indexOn 可以是字符串值数组。您现在实际上只有一个字符串值。

    所以替换:

    ".indexOn": ["category,author"]
    

    与:

    ".indexOn": ["category", "author"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-13
      • 2018-06-13
      • 2012-10-10
      • 2021-09-17
      • 2013-06-29
      • 2020-03-25
      • 2021-02-22
      • 2016-04-30
      相关资源
      最近更新 更多