4

Is it possible to create rules denied if a price is already registered in the database? I tried to validate using exist data but firebase blocks all of them when there is one data

database.ref('data/penawaran/enter-name').push({
    name: 'Udin',
    price:'300000',
    member_id:9,
    product_id:8,
    created_at: '2020-10-13 23:00:00'
}, function(error) {
    if (error) {
       alert('error');
    } else {
       
    }
});

^^^ i want get failed cause price 300000 already exist in database

database.ref('data/penawaran/enter-name').push({
    name: 'Udin',
    price:'900000',
    member_id:9,
    product_id:8,
    created_at: '2020-10-13 23:00:00'
}, function(error) {
    if (error) {
       alert('error');
    } else {
       
    }
});

i want get success cause price 900000 not exist in database

enter image description here

enter image description here

6
  • Since the rules by themselves don't do anything, you should edit the question to also show the app code that doesn't work the way you exepct. Commented Oct 11, 2020 at 21:49
  • hello im already edit the question and add the app code, thank you :) Commented Oct 11, 2020 at 21:59
  • We need to be able to see the complete, minimal code. We can't see how you build the reference, since we don't know what roomName is, or any of the other variables. You should hard code all variables with actual values. Commented Oct 11, 2020 at 22:11
  • hello thank you, im already update my example code Commented Oct 11, 2020 at 22:22
  • 1
    There is no way to ensure a unique value in the database through security rules. I you want something to be unique, make it the key - since keys are by definition unique within their context. Commented Oct 12, 2020 at 5:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.