I have the following data structure:
{"applicants":[
{
"-KNbKoNzPGsz2TAQp-j9" : {
"email" : "zahavi@post.tau.ac.il",
"id" : "056042344",
"name" : "Jacob",
"prefix" : "Prof.",
"surname" : "Zahavi"
},
"-KNbWPpsrFGJBDaWK2EN" : {
"email" : "chamud@gmail.com",
"id" : "314965211",
"name" : "Ilay",
"prefix" : "Mr.",
"surname" : "Shvo"
},
"-KNd8HvkzAYi0LtG9qNj" : {
"email" : "zahavi@zpost.tau.ac.il",
"id" : "056042344",
"name" : "Jacob",
"prefix" : "Prof.",
"surname" : "Zahavi"
}]
}
}
I would like to enforce uniqueness rule on the field id, so it will not be possible to create two entries in applicants collection that has the same id value.
currently my rules are:
{
"rules": {
".read": true,
".write": true,
"Tables":{"applicants":{"id":{".indexOn":".value"}}}
}
}
I explored two possible solutions that are: 1. transaction. unfortunately i did not find a way to run transaction from a query. 2. rules. but failed to find something suitable.
Edit (from comments):
I tried the following rules:
{
"rules": {
".read": true,
".write": true,
"Tables": {
"applicants": {
"$app": {
"id": {
".indexOn": ".value",
".validate": "!root.child('Tables').child('applicants').child(newData.child('id').val()).exists()"
},
}
}
}
}
}
and I always got creation failed permission denied even for values that were not exist