在firestore集合中,如何防止auth用户在集合中添加太多文档?

问题描述 投票:0回答:1

我在消防站有一个收藏品。已有规则允许用户在集合中添加文档。

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: false
      allow write: false
      allow update: false
      allow delete: false
    }

    match /users/{userId}/widgets/{widgetId} {
      allow read: if request.auth.uid == userId
      allow delete: if request.auth.uid == userId
      allow update: if request.auth.uid == userId
      allow create: if request.auth.uid == userId
    }
  }
}

如何防止用户添加100多个文档?

firebase google-cloud-firestore firebase-security-rules
1个回答
0
投票

没有简单的规则可用于限制集合中的文档数。添加时,您将不得不使用另一个文档来保持运行总计,然后在规则中检查该文档的内容,以确定是否将超出限制。

或者,您可以让客户端调用服务器端函数来编写文档,并且它可以(以自己的代码检查)集合是否太大。

© www.soinside.com 2019 - 2024. All rights reserved.