我正在通过表格收集数据使用输入类将其保存到流星集合(工作正常)。现在我想防止重复输入“电子邮件”& “类别”组合(用户不能两次从同一电子邮件申请类别)。请帮忙。!!
另请告诉我如何使用填写的表单生成感谢警报
/*Meteor JS File*/
Info = new Meteor.Collection("info");
if (Meteor.isClient) {
Template.add_info.events({
'submit form':function(){
Info.insert({
category:$('.the_item11').val(),
name:$('.the_item1').val(),
mobile:$('.the_item2').val(),
Mail:$('.the_item3').val(),
createdAt: new Date(),
});
if ($.trim($("#uname").val()) === "" || $.trim($("#umobile").val()) === ""){
alert('you did not fill out one of the fields');
return false; }
alert("Thank You For Registering")
}
});
}
/*HTML form*/
<head>
<title>yahaviform</title>
</head>
<body>
<img src="EDMcrowd.jpg" name="CA_5" id="CA_5"/>
<h1 id="reg">Register here</h1>
{{> add_info}}
</body>
<template name="add_info">
<div id="d1">
<form>
<label>You are</label><br>
<select class="the_item11" id="ucat" required>
<option></option>
<option>DJ</option>
<option>Singer</option>
<option>Instrumentalist</option>
<option>Band</option>
</select> <br>
<label>Name</label><br>
<input type="text" class="the_item1" id="uname" required><br>
<label>Mobileno.</label><br>
<input type="tel" class="the_item2" id="umobile" required><br>
<label>EmailID</label><br>
<input class="the_item3" type="email" id="umail" required><br>
<br>
<input type="submit" value="Register">
</form>
</div>
</template>
答案 0 :(得分:0)
您可以使用compound unique索引:
db.my_collection.ensureIndex(
{
email: 1,
category: 1
},
{
unique: 1
}
)
答案 1 :(得分:0)
查看精彩包meteor-autoform