firebase - Check if other node has same child node value -


i'm trying implement validation rule check when new $resvs created if other $resvs contains same eventkey (which child node of object) existing reservations nodes.

the following code not working, can't come better now:

"reservations": {           "$resvs": {             ".write": "!data.exists() || newdata.child('eventkey').val() == root.child('reservations/$resvs/eventkey').val()"   } } 

edit:

firebase.database().ref('/reservations').push({         name: name,         number: number,         email: email,         start: start,         end: end,                    scheduleid: scheduleid,         schedulename: schedulename,         eventkey: eventkey,         placeid: placeid     }).then(function(){       $('#calendar').fullcalendar('refetchevents'); //confirmaton first? todo     }).catch(function(error){       alert('err');     }); 

to solve problem, recomand change database structure little bit. instead of using event key field, try store reservation data directly under event key. in way can double check, once in code , once using security rules. if want check in code, add listener on reservations node , use exists() method on datasnapshot object. in same manner use security rules, because actual database structure it's impossible use wildcards in way want.

your database new structure should this:

firebase-root      |      --- reservations               |               --- eventkey1               |      |               |      --- //event1 details               |               --- eventkey2                      |                      --- //event2 details 

but remember, work , if the event key unique.

hope helps.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -