javascript - Onclick 如何在 mongodb 中查找和更新投票?
问题描述
我正在创建一个投票系统,但我似乎无法找到一种方法来做我想做的事情(或者我正在寻找错误的事情)。基本上我正在尝试点击甚至触发此代码,而不是使用我的虚拟代码
{"_id": ObjectId("5b7b67247a3b516f8cb0c7d9")}
我希望它从我单击的那个中获取 ObjectId。我应该将其分配给 HTML 中的 ID 吗?
upvote: function(req, res, next){
let userId = db.get().collection('users').findOne({"_id": ObjectId("5b6a39ff17e9af6c20b9c5a8")});
let gameId = db.get().collection('matches').findOne({"_id": ObjectId("5b7b67247a3b516f8cb0c7d9")});
userId.then(function(upvotedata){
if(upvotedata){
db.get().collection('matches').updateOne({"_id": ObjectId("5b7b67247a3b516f8cb0c7d9")}, { "$inc": { "currentvote": 1}});
res.status(200).json();
} else {
return res.sendStatus(400);
}
});
gameId.then(function(game){
if(game){
} else {
return res.sendStatus(400);
}
});
},
<div class="row game-cards featured-game front">
<div class="container col-lg-6">
<canvas id="game-circles"></canvas>
</div>
<div class="col-lg-6 game-info">
<h6 class="text-center">{{topmatch.AwayTeam}} @ {{topmatch.HomeTeam}}</h6>
<p class="text-center">{{topmatch.MatchTime}}</p>
<h6 class="text-center">Total Points Bet</h6>
<h5 class="text-center">500</h6>
<form>
<div class="form-group text-center">
<label for="home-team">{{topmatch.HomeTeam}} {{topmatch}}</label>
<input type="number" class="form-control text-center" placeholder="Home Team Bet">
</div>
<div class="form-group text-center">
<label for="away-team">{{topmatch.AwayTeam}} {{topmatch.Odds.PointSpreadAway}}</label>
<input type="number" class="form-control text-center" placeholder="Away Team Bet">
</div>
<button type="submit" class="btn btn-primary btn-block">Submit</button>
<button type="button" class="btn btn-secondary btn-block play-with-friends">Play With Friends</button>
</form>
</div>
<div class="col-lg-12">
<div class="row">
<div action="/api/upvote" method="post" id="super1"><i id="super" class="fas fa-chevron-circle-up color-gray upvote {{topmatch.ID}}"></i></div>
<div class="margin-left"><i onclick="upvote()" id="super" class="fas fa-chevron-circle-down color-gray downvote {{topmatch.ID}}"></i></div>
<div class="margin-left"><p class="vote-number" id="green">{{topmatch.currentvote}}</p></div>
</div>
</div>
</div>
解决方案
推荐阅读
- html - 取消提示后保持模式打开
- python - 如何在不重新加载页面的情况下从 Angular Safeurl 强制即时图像刷新
- firebase - 使用 ESP32+Sim800L 向 Firebase 发送传感器数据
- javascript - 无法理解这个特定的 Array reduce 方法
- javascript - 传输加速是否有效?响应位置和对象 URL 不同
- javascript - 为什么在 head 元素中使用匿名函数?
- jquery - 必填字段在 Select2 选择框中不起作用
- sql-server - SQLLab - Apache Superset 中是否允许 CTE?
- react-native - 当我在 QR 中触摸时如何隐藏底部选项卡,(我的 QR 图标选项卡无法完全隐藏,因为它比选项卡栏大)
- ohif - 使用 OHIF Embedded Viewer 时如何直接加载研究