有没有一种方法可以使用安全规则来检查 Cloud Firestore 集合的大小?

huangapple go评论65阅读模式
英文:

Is there a way to check the size of a Cloud Firestore collection using Security Rules?

问题

在我的应用程序中,每个用户在我的数据库的用户集合中都有一个文档。在每个用户的文档下,都有一个用于该用户上传的食物的子集合。默认情况下,我希望限制用户不能向其个人子集合中添加超过25种食物。是否可以通过安全规则检查集合大小是否<= 25?

英文:

In my app, each user has a document in the users collection of my database. Under each user's document, there is a subcollection for that user's uploaded foods. By default, I want to limit it so that the user cannot add more than 25 foods to their personal subcollection. Is there a way to check via Security Rules if the collection size is <= 25?

答案1

得分: 0

这在安全规则中是不可能的。

如果您想要文档计数,您将需要在一个单独的文档中自行管理它。然后,您可以编写规则来检查您在该文档中管理的计数。

英文:

It's not possible in security rules.

If you want a document count, you will have to manage one of your own in a single document. Then you could write rules to check against the count that you manage in that document.

huangapple
  • 本文由 发表于 2020年8月9日 06:22:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63320761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定