문제

I have a security rule for adding new data

 "CATEGORIES": {
      "$CATEGORIES": {
      ".write":   "root.child('USERS/' + auth.uid + '/type').val() == 'admin' && !data.exists() || root.child('USERS/' + auth.uid + '/type').val() == 'admin' && root.child('MODES/delete').val() == 'yes'",
       "$DATA": {
         ".write":   "root.child('USERS/' + auth.uid + '/type').val() == 'admin'",
       }
      }
      }

It's used to prevent duplicates or overwriting of the child node with the !data.exists() rule.

Problems is, it wont let me delete the child with this rule because data exists. To get around this I added the root.child('MODES/delete').val() data to allow me to delete it if I set it to 'yes'.

How can I have it so I don't have to do this work around? So I can have no duplicates but also be able to delete the child if I want to?

도움이 되었습니까?

해결책

To allow creates but no overwriting, !data.exists() works fine. To allow deletes, you can use !newData.exists().

So all together:

// create or delete, but no update/overwrite
".write":  "!data.exists() || !newData.exists()"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top