有没有办法限制firebase中的孩子数量? [英] Is there a way to limit the number of children in firebase?

查看:113
本文介绍了有没有办法限制firebase中的孩子数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我经常推动的火力基地,就像聊天一样,我担心在火力基地聚集的孩子的数量。当所有的连接都没有了,但是有没有办法限制它们的数量呢?



干杯!

解决方案

您可以使用环缓冲。如果您想要的节点不超过50个,则可以让节点的子节点为/ 0,/ 1,/ 2,... / 49,并在生成数据时写入这些节点。使用 交易() 您然后可以在Firebase中的其他位置跟踪当前的开始和结束。优先级也可以与这种方法一起使用,以保持这种有序(例如,通过时间戳)。这种方法也有利于在数据不断增长的时候修剪数据。

我们目前没有使用服务器端安全规则来强制执行此操作的机制,但是我们已经在我们的内部跟踪器中记录了它。


I have a firebase into which i'm pushing quite regularly, much like a chat, and i'm concerned about the number of children gathering in the firebase. They are all removed when all the connections are gone but is there a way to limit the number of them in there?

Cheers!

解决方案

You could implement something like this using a ring buffer. If you wanted to have no more than 50 nodes, you could have children of a node referenced as /0, /1, /2, ... /49, and write to those as data is being generated. Using a transaction() you could then have another location in Firebase keep track if current 'start' and 'end'. Priorities could also be used in conjunction with this approach to keep this ordered (for example, by timestamp.) This approach would also have the benefit of not having to prune the data as it grew.

We don't currently have a mechanism to enforce this using server-side security rules, but I've made a note of it in our internal tracker.

这篇关于有没有办法限制firebase中的孩子数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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