firebase 错误考虑添加“.indexOn”:

firebase Error Consider adding ".indexOn":

我在 swift 中使用 firebase 从 firebase 实时数据库中读取一些数据。当我在 firebase 面板中有一个项目时它工作正常,但在今天添加另一个项目后我得到了这样的错误

2017-09-23 00:15:18.360 AfgDate[2816] [Firebase/Database][I-RDB034028] Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "date" at /data to your security rules for better performance

这是我的数据库结构

我的角色是

    {
  "rules": {
    ".read": true,
    ".write": true,
  }
}

之后我把我的角色改成了这个

  {
"rules": {
    "data": {
      ".indexOn": "date",
        ".read": true,
        ".write": true
    }
  }
}

这次我也无法读取数据,而且我在控制台中也没有看到任何错误 这是我在 swift

中的代码
ref = Database.database().reference()
    ref.child("data").queryOrdered(byChild: "date").queryEqual(toValue: "1396/06/05").observeSingleEvent(of: .value, with: { (snapShot) in
        if let snapDict = snapShot.value as? [String:AnyObject]{

            for each in snapDict{
                let key  = each.key as String
                let date = each.value["date"] as!String
                let name = each.value["text"] as! String
                print(key)
                print(name)
                self.lblshow.text = name
            }
        }
    }, withCancel: {(Err) in

        print(Err.localizedDescription)

    })

如何

您的数据库图像显示 Data 为大写,但您的 .indexOn data 不是。你希望你的规则是这样的:

{
"rules": {
    "Data": {
      ".indexOn": "date",
        ".read": true,
        ".write": true
    }
  }
}

我刚才自己测试了几个规则,发现它们是区分大小写的。

*请研究评论以了解问题的实际解决方式。

试试这个,并在规则和查询中使用相同的 Data(大写“D”),就像 Jen 建议的那样。

 {
    "rules": {
         ".read": true,
         ".write": true,    
         "Data" : {
             ".indexOn": "date"
         }
         
        }
    }

然后试试这个

var ref: FIRDatabaseReference!
ref = FIRDatabase.database().reference()

而不是

ref = Database.database().reference()