【问题标题】:firebase indexOn for child valuesfirebase indexOn 用于子值
【发布时间】:2018-12-14 11:25:49
【问题描述】:

我正在尝试使用如下的 firebase 查询来获取所有心情等于 M1 的帖子:

db.ref(`Recommendations`).orderByChild(`post/vote/moodTags/${idMood}/key`).equalTo(`${idMood}`).once('value').then(recs =>{
        //Número de recs con el mood
        let recsCount = recs.numChildren();
        console.log(`Número de recs encontradas --> ${recsCount}`);
        ...
    });

和 firebase 控制台显示警告:

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

但是,我在 firebase 站点的索引规则是:

"Recommendations":{
  ".indexOn": ["post/userFirebaseKey","post/user/firebaseKey","userFrom/firebaseKey","post/location/placeId","firebaseKey","placeId"],
  "post":{
    "vote":{
      "moodTags":{
        "$moodId":{
          ".indexOn": "key"
        }
      }
    }
  }
}

那么,当我使用子级别时,我如何才能真正指定 indexOn 规则?

我的数据库:

+ Recommendations
  + idRec
    property1:''
    property2:''
    property3:''
    + post
      property21:''
      ...
      + vote
        + moodTags
          + M1
            key:'M1'
            name:''
            url:''
          + M2        
            ...

【问题讨论】:

  • @valhallarossferrer 还不够,文档非常简单和琐碎。我需要的有点不同。这就是为什么我提出我已经实施的规则。

标签: javascript node.js firebase firebase-realtime-database


【解决方案1】:

您似乎在那里操作的级别太深了:毕竟您想要索引 moodTags 列表,而不是 one moodTag 的内容。

这意味着您的规则必须看起来更像这样:

"Recommendations":{
   ".indexOn": ["post/userFirebaseKey","post/user/firebaseKey","userFrom/firebaseKey","post/location/placeId","firebaseKey","placeId"],
  "post":{
    "vote":{
      "moodTags":{
          ".indexOn": "key"
        }
      }
    }
  }
}

您可以在the official Google Firebase Docsthis helpful article on Mediumthis Google Groups post where someone had a similar issue 中阅读这些索引规则。

【讨论】:

    猜你喜欢
    • 2017-07-19
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多