我的网站上有一个表单,用户可以在该表单中输入一个数字subNum.当用户提交表单时,我想检查他们输入的值是否已作为任何现有文档中的值存在.这都是在javascript/meteor中完成的
所有表单数据都放入这样的对象:
participantObject = {
subNum: parseInt(number)
}
Run Code Online (Sandbox Code Playgroud)
然后,此对象作为文档插入到Participants集合中
单击提交按钮时,我需要检查他们输入的数字是否已经输入(即作为subNum任何文档中的值存在).如果是这样,请阻止表单提交并显示错误
我正在尝试这样的检查:
var existingSubs = Participants.find(
{subNum: {$eq: participantObject.subNum}}
).count();
console.log(existingSubs);
Run Code Online (Sandbox Code Playgroud)
我希望上面会找到我所有的文件,其中subNum等于输入的值(participantObject.subNum),并且控制台记录匹配文件的数量
问题是在控制台日志中我看到了 Unrecognized operator: $eq
我是否错误地使用了相等运算符?
有没有更有效的方法来执行这样的检查?
目前我正在开发一个基于Meteor的项目作为后端,React作为前端.我真的很喜欢简单,直到我删除insecure包并且必须处理Meteor方法.现在我需要执行一个基本的插入操作,我只是被卡住了!我有一个表单作为组件(如果最终我想使用此表单不仅用于插入项目,而且还用于编辑这些项目)这里是我的代码:
AddItemForm = React.createClass({
propTypes: {
submitAction: React.PropTypes.func.isRequired
},
getDefaultProps() {
return {
submitButtonLabel: "Add Item"
};
},
render() {
return (
<div className="row">
<form onSubmit={this.submitAction} className="col s12">
<div className="row">
<div className="input-field col s6">
<input
id="name"
placeholder="What"
type="text"
/>
</div>
<div className="input-field col s6">
<input
placeholder="Amount"
id="amount"
type="text"
/>
</div>
</div>
<div className="row">
<div className="input-field col s12">
<textarea
placeholder="Description"
id="description"
className="materialize-textarea">
</textarea>
</div>
</div>
<div className="row center">
<button className="btn waves-effect waves-light" type="submit">{this.props.submitButtonLabel}</button>
</div>
</form>
</div>
);
}
}); …Run Code Online (Sandbox Code Playgroud)