如何为Firebase中的动态键写入.indexOn? [英] How to write .indexOn for dynamic keys in firebase?

查看:287
本文介绍了如何为Firebase中的动态键写入.indexOn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据:

 任务:{
组1:{
pushid1:{
date:18921949021,
title:做点什么
},
pushid2:{
date:18921949021,
title:Do别的东西
}
},
第二组:{
pushid3:{
日期:18921949021,
标题:做另一件事






$ b我引用了它的日期,获得一定时间后的任务。

  var now = Date.now(); 
var taskRef = new Firebase(FB +/ tasks /+ thisGroup);
taskRef.orderByChild('date')。startAt(now).on(child_added,function(snap){
console.log(snap.val());
}) ;

这一切都正常,对于每个组我都会收到警告消息,如下所示:

  FIREBASE警告:使用未指定的索引。考虑在任务/组1添加.indexOn:date到您的安全规则以获得更好的性能

我如何将其添加到我的安全规则?我不能为每个用户组添加一个,是否有某种类型的通配符?

解决方案

您正在寻找:

$ $ $ $ $ $ $ $ $ $ $.read:true,
.write :true,
rules:{
Tasks:{
$ groupid:{
.indexOn:date
} $ b Firebase文档通常很不错读。在安全指南中花费一个小时或更少时间,将确保您拥有更好地了解这个和其他许多主题。

I have data set up like this:

Tasks:{
  Group 1:{
    pushid1:{
      date: 18921949021,
      title: "Do something"
    },
    pushid2:{
      date: 18921949021,
      title: "Do something else"
    }
  },
  Group 2:{
    pushid3:{
      date: 18921949021,
      title: "Do another thing"
    }
  }
}

I reference it by date so I only get the tasks made after a certain time.

var now = Date.now();
var taskRef = new Firebase(FB + "/tasks/" + thisGroup);
taskRef.orderByChild('date').startAt(now).on("child_added", function(snap){
  console.log(snap.val());
});

This all works fine, for each group I get a warning message saying something like this:

FIREBASE WARNING: Using an unspecified index.  Consider adding ".indexOn": "date" at tasks/Group 1 to your security rules for better performance

How do I add that to my security rules? I can't add one for each group a user makes, is there a wild card entry of some type?

解决方案

I guess you're looking for:

{
  ".read": true,
  ".write": true,
  "rules": {
    "Tasks": {
      "$groupid": {
        ".indexOn": "date"
      }
    }
  }
}

The Firebase documentation is usually a pretty good read. Spending an hour or less in the security guide, will ensure you have a better understanding of this and many other topics.

这篇关于如何为Firebase中的动态键写入.indexOn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆