Home > front end >  can you check the size of object keys in firestore similar to an array using .size()?
can you check the size of object keys in firestore similar to an array using .size()?

Time:01-28

I am trying to created and object that will have a key and a related array to that key, the idea is I want to limit the amount of keys so it wont pass 10 and if it does the write will fail can I implement this using security rules ?

const obj = {
key1 : []
key2 : []
key3 : []
...rest
key10 : []
}

sure I can do client side block but want to make sure this object wont grow indefinity.

CodePudding user response:

A Map also has size() method that returns number of keys in it. The following should work:

match /images/{snippetId} {
  allow write: if request.resource.data.mapField.size() <= 10;
}

This will reject write operations if mapField has more than 10 keys.

  • Related