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

Viewed 249

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?

2 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']

The complete list of things you can do with Set is in the linked API documentation. Same thing with List.

As you can see, there are no element accessors available with Sets. All you can do is check size and existence, and manipulate contents.

For Lists, you must know the index of the element to get something. If you don't know the index, then you can't access it.

Neither collection offers a function to "get an arbitrary, unnamed, unindexed item".

Related