Onclick如何在mongodb中查找和更新投票?

时间:2018-09-13 20:40:03

标签: javascript node.js 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>

0 个答案:

没有答案