本文介绍了将数组大小限制为最多 N 个索引(安全规则)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下最大数组大小:
Consider the following maximum array size:
现在假设用户执行 push() childByAutoId.我期望发生的是
Now let's say a user performs a push() childByAutoId. What I expect to happen is
if (arraySize > arraySizeLimit) { // Delete first Index }我对 Firebase 安全规则还很陌生.我做了一些阅读,但仍在为此苦苦挣扎.我为没有任何尝试"而道歉要呈现的代码.
I am fairly new to firebase security rules. I did some reading but still struggling with this. I apologise for not having any "attempt" code to present.
推荐答案安全规则无法像这样检查列表的大小.
There's no way for security rules to check the size of a list like that.
我所知道的主要选项是:
Th main options that I know of, are:
- Kato 对这个问题的古老回答,它使用已知的节点名称来施加限制:限制可以写入路径的记录数(在安全规则中引用其他路径)
- 这个扩展或云函数,将子节点的数量减少到最大配置/em> 写操作超出了这个数字.
- 通过应用调用的单个云函数执行写入.在 Cloud Functions 中,您将读取整个消息节点并根据需要截断它.
- Kato's age-old answer to this question, which uses known node names to impose a limit: Limit number of records that can be written to a path (reference other paths in security rules)
- This extension or Cloud Function that reduces the number of child nodes to the maximum configured after a write operation goes beyond that number.
- Perform the write through a single Cloud Function, which the app calls. In the Cloud Function you'd then read the entire messages node and truncate it as needed.
更多推荐
将数组大小限制为最多 N 个索引(安全规则)
发布评论