Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase security rules to check array length

Is it possible to enforce the votes array to have exactly 5 entries?

newData.child('votes').val().length === 5) doesn't seem to work as the length property only works with strings. Here is my data:

votes
   $voteID
     page:"12345"
     user: "facebook:1234567"
     votes: {
       -K3M2kpTEtXRk-sHV6FO: true
       -K3M2kp_5vZDCZKUke2M: true
       -K3M2kpe7l22mYA1dc6D: true
       -K3M2kqhpgehSSUAcFLl: true
       -K3M2krABl2tU-cekpDA: true
    }

Is it possible at all to enforce this validation ?

like image 654
Fred John Avatar asked Apr 27 '26 06:04

Fred John


1 Answers

How about

"!newData.hasChild('X')"

where X is the length you want +1

and for further validation like you specified you can always do

"$index" : { 
   ".validate" : "... some validation .. "
}

so my answer does not limit you in any way and can support to any array limit

like image 189
guy mograbi Avatar answered Apr 28 '26 21:04

guy mograbi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!