将数组大小限制为最多 N 个索引(安全规则) [英] Restrict an array size up to N indices (Security Rules)

查看:22
本文介绍了将数组大小限制为最多 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'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 个索引(安全规则)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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