Search code examples
firebasegoogle-cloud-firestorefirebase-security

Firestore hasOnly Rules


enter image description here

This is my database , how can I allow access only to 'name' field in map array

I found and use this rule , but only works on field :

Allow a client to update only these 1 fields in a document

&&(request.resource.data.diff(resource.data).affectedKeys()
        .hasOnly(['Devices']))

Solution

  • What you're trying to do is not possible with Firebase security rules. You can't target the values of maps in arrays for use in rules.

    You will have to do one of the two things:

    1. Convert your array into a subcollection of documents rather than an array of maps.
    2. Convert the array of maps into two arrays of values (names and IDs separately).