Firebase unable to write Security Rules for Unique Data -
i want vannumber
unique
//vanwithagent after root "/vanwithagent" vanwithagent : { "-kshjydyi49rpzwskdg1" : { // "agentmobile" : "sdfs", "agentname" : "sdfsdf", "isagentassignedwithtask" : false, "vanname" : "fsdf", "vannumber" : "sf", "vanpresentlocation" : { "currlattitude" : "n/a", "currlongitude" : "n/a", "pin" : "n/a" } } }
rules have written:
{ "rules": { //rules ".read": "auth != null", ".write": "auth != null", "vanwithagent": { "$vanwithagentid": { "vannumber":{ ".validate":"!(root.child('vanwithagent').child(data.child('vannumber').val()).exists())" } } } } }
you cannot check if value exists in collection of values within firebase's security rules. can check if key exists and if key has value. don't in data model.
as usual solution pick data model matches requirements. if vans unique , have id, store list keyed under id:
vanwithagent : { "sf" : { // vannumber "agentmobile" : "sdfs", "agentname" : "sdfsdf", "isagentassignedwithtask" : false, "vanname" : "fsdf", "vanpresentlocation" : { "currlattitude" : "n/a", "currlongitude" : "n/a", "pin" : "n/a" } } }
this data structure guarantees van number unique, without writing security rules it.
Comments
Post a Comment