Using firebase database rules to prevent negative values -


i trying use firebase database rules prevent negative values.

{ "rules": {     "products": {         ".read": true,         ".write": "auth != null",         ".indexon": ["subgroup", "group", "visibility"],         ".validate": "newdata.child('quantity').val() >= 0"     } } 

however, using the simulator test rule, seeing write denied on validate rule:

".validate": "newdata.child('quantity').val() >= 0" 

i using:

location: /products/-kq1qlkei3gefugsfil_ 

and

{    "quantity": 0 } 

i using authenticated user.

any idea whats going on here ?

thanks.

==== update:

changing rules following didn't help:

"products": {         "$product": {         ".read": true,         ".write": "auth != null",         ".validate": "newdata.child('quantity').val() >= 0",         ".indexon": ["subgroup", "group", "visibility"]       }     },  

also, db design:

dbroot     products         -kq1npkleqitmzezhrfw             description:"limited edition"             quantity: 5             ... 

your validation rules on /products, writing /products/[autoid]. try modifying rules so:

{   "rules": {     "products": {        "$pid": {          ".read": true,          ".write": "auth != null",          ".indexon": ["subgroup", "group", "visibility"],          ".validate": "newdata.child('quantity').val() >= 0"        }     }   } } 

simulated rules


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -