Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert a set into a list in firestore security rules?

i need to get an item from a set returned from

resource.data.diff(request.data).changedKeys()

so, is there a way to get an item from a set, or turn a set into a list to get an item?

I don't need to compare any values, so i don't need hasOnly() or any related functions, i need to get one of the values in a set, any way to do this?

like image 850
shmibbles Avatar asked Sep 17 '25 04:09

shmibbles


1 Answers

I raised a ticket to Firebase support to make Set's values accessible as soon as Set was added to the API. Still waiting...

The workaround I use is request.writeFields, which contains all the fields that are written to for a given create/update.

Note:

  • request.writeFields is deprecated and may be removed (crazy in my opinion when there is no other workaroung available)

  • For nested fields it will give you the full path for each field For instance if you update the following fields in your doc:

    {
      A              // UPDATED
      B: {
       BA
       BB            // UPDATED
      }
      C: {
        CA: {
          CAA        // UPDATED
        }
        CB
      }
    }
    

=> request.writeFields = ['A', 'A.BB', 'C.CA.CAA']

like image 101
l1b3rty Avatar answered Sep 21 '25 09:09

l1b3rty