如果用户输入 mongodb 中的表单相等对象,则返回 true

发布于 2025-01-11 06:34:42 字数 1691 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文