如何防止重复?我曾尝试使用快照,但没有成功。如果数据库中存在电子邮件和电话号码,有人可以帮助我设置规则并防止重复吗?
function submitForm(e){
e.preventDefault();
// Get values
var name = getInputVal('name');
var company = getInputVal('company');
var email = getInputVal('email');
var phone = getInputVal('phone');
var message = getInputVal('message');
// Save message
saveMessage(name, company, email, phone, message);
}
// Function to get get form values
function getInputVal(id){
return document.getElementById(id).value;
}
// Save message to firebase
function saveMessage(name, company, email, phone, message){
var newMessageRef = messagesRef.push();
newMessageRef.set({
name: name,
company:company,
email:email,
phone:phone,
message:message
});
}
这是我设定的规则
{
"rules": {
".read": "false",
".write": true
}
}