Firebase即使正确使用.indexOn也未定义索引?

问题描述 投票:0回答:1

我收到错误消息:

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-rules
1个回答
0
投票

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

因此替换:

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

使用:

".indexOn": ["category", "author"]
© www.soinside.com 2019 - 2024. All rights reserved.