简体   繁体   中英

Firestore Security Rule for allowing only one document

I have a collection that should have only one document or none.

Is it possible to create a security rule to validate this condition?

I want to block an add if there's a document there already. In that case only an update is allowed.

It's not possible to do this with security rules without also adding another document that maintains the count of documents, and adding more security rules to require that its count stay up to date. (It doesn't have to be a count - it could be a boolean - but it will have to be atomically up to date regardless.)

See also: How do you force a Firestore client app to maintain a correct document count for a collection?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM