Firebase 在firestore集合中,如何防止身份验证用户在集合中添加过多文档?

Firebase 在firestore集合中,如何防止身份验证用户在集合中添加过多文档?,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,我在一家消防商店里有一件收藏品。有一些规则允许用户在集合中添加文档 service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read: false allow write: false allow update: false allow delete: false } match /us

我在一家消防商店里有一件收藏品。有一些规则允许用户在集合中添加文档

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个文档?

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

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