【问题标题】:Firebase indexOn warning for dynamic valuesFirebase indexOn 动态值警告
【发布时间】:2017-07-19 07:01:41
【问题描述】:

这是我的 Firebase 数据库结构和查询。

我对这个结构的查询是:

var messageRef = databaseRef.child(`/messagesThread/-KdzCvVW5icW7ZuSIAxV`);

messageRef.orderByChild(`/readBy/{userId}`).equalTo(false).on("child_added", (snapshots)=>{
  console.log("Unread messages = " + snapshots.numChildren());
});

但上面的查询给了我警告

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "readBy/{userId}".

那么如何用动态{userId}添加这个indexOn呢?

【问题讨论】:

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


    【解决方案1】:

    由于通配符上的索引不是很好,你可以修改结构然后索引:

    ---readBy-+
              |
               294jjfouurjkfJDGLS+
                                 |
                                isRead: true
    

    现在您可以添加安全规则了:

    "readBy": {
      ".indexOn": "isRead"
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-09
    • 2017-01-07
    • 2020-08-03
    • 2018-12-14
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多