如果用户输入 mongodb 中的表单相等对象,则返回 true
我有一个 EJS 页面设置,用户可以使用按钮/文本进行各种选择,并且基于这些选项,我想查询 mongoDB 集合,并在用户输入与对象中的数据匹配时返回 true?
表单
<% layout('/layouts/boilerplate')%>
<form action="/caddy" method="get">
<div class="position">
<label for="tablePosition">Hero Position</label>
<input type="text" class="form-control" placeholder="Enter Your position" aria-label="Example text with two button addons">
<button type="button" class="btn heroBTN" id="btn">UTG</button>
<button type="button" class="btn heroBTN" id="btn">HJ</button>
<button type="button" class="btn heroBTN" id="btn" >LJ</button>
<button type="button" class="btn heroBTN" id="btn">CO</button>
<button type="button" class="btn heroBTN" id="btn">BTN</button>
<button type="button" class="btn heroBTN" id="btn">SB</button>
<button type="button" class="btn heroBTN" id="btn">BB</button>
</div>
<div>
<button submit="button" class="btn btn-primary">submit</button>
</div>
</form>
架构
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const RangesSchema = new Schema({
position: String,
playertype: String,
unsuited_hands: [String],
suited_hands: [String]
});
module.exports = mongoose.model('Ranges', RangesSchema);
JS
router.get('/caddy', function(req, res) {
db.collection('rFI').find({"Position": { $regex: req.query.position ,$options: 'i' }}).toArray( (err, results) => {
console.log('got search')
res.send(results)});
});
I have a EJS page setup whereby a user makes various selections using buttons/text, and based on those options i want to query a mongoDB collection and return true if the users inputs match the data in an object?
form
<% layout('/layouts/boilerplate')%>
<form action="/caddy" method="get">
<div class="position">
<label for="tablePosition">Hero Position</label>
<input type="text" class="form-control" placeholder="Enter Your position" aria-label="Example text with two button addons">
<button type="button" class="btn heroBTN" id="btn">UTG</button>
<button type="button" class="btn heroBTN" id="btn">HJ</button>
<button type="button" class="btn heroBTN" id="btn" >LJ</button>
<button type="button" class="btn heroBTN" id="btn">CO</button>
<button type="button" class="btn heroBTN" id="btn">BTN</button>
<button type="button" class="btn heroBTN" id="btn">SB</button>
<button type="button" class="btn heroBTN" id="btn">BB</button>
</div>
<div>
<button submit="button" class="btn btn-primary">submit</button>
</div>
</form>
Schema
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const RangesSchema = new Schema({
position: String,
playertype: String,
unsuited_hands: [String],
suited_hands: [String]
});
module.exports = mongoose.model('Ranges', RangesSchema);
JS
router.get('/caddy', function(req, res) {
db.collection('rFI').find({"Position": { $regex: req.query.position ,$options: 'i' }}).toArray( (err, results) => {
console.log('got search')
res.send(results)});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论