将数组大小限制为最多 N 个索引(安全规则)

编程入门 行业动态 更新时间:2024-10-08 01:25:58
本文介绍了将数组大小限制为最多 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 个索引(安全规则)

本文发布于:2023-11-30 15:18:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650481.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最多   数组   索引   大小   规则

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!