Firestore Security Rules - how to prevent modification of a certain field

前端 未结 1 689
野的像风
野的像风 2020-12-11 23:56

Let\'s assume we have a Firestore collection called todos, where each todo will look something like this:

{
    name: \"Buy milk\",
    complete         


        
相关标签:
1条回答
  • 2020-12-12 00:39

    At "Writing conditions for Cloud Firestore Security Rules" section "Data validation" example #2

    service cloud.firestore {
      match /databases/{database}/documents {
        // Make sure all cities have a positive population and
        // the name is not changed
        match /cities/{city} {
          allow update: if request.resource.data.population > 0
                        && request.resource.data.name == resource.data.name;
        }
      }
    }
    

    So request.resource.data.user == resource.data.user should work for you? CMIIW

    Ref: https://firebase.google.com/docs/firestore/security/rules-conditions#data_validation

    0 讨论(0)
提交回复
热议问题