I want to write a rule that will don't allow add same document second time

后端 未结 2 1270
醉酒成梦
醉酒成梦 2021-01-28 03:54
rules_version = \'2\';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{usersID} {
    allow read;
    allow write: if request.auth.         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 04:22

    What you are trying to do is not possible with security rules. This would require that you be able to perform a query on desksCollection for documents that match the criteria of having a field with a certain value. However, performing queries is not possible in security rules. You can fetch a document by its ID, but that won't help you here, because you don't know which document to fetch.

    If you require that deskName be unique, then consider using that value as the ID of the document. Then you can write a rule to prevent updates if the document already exists.

提交回复
热议问题