因此,我试图找出一种正确的方法,只需单击一个投票按钮,即可找到“此” ID。最好的方法是什么?现在,我只是使用虚拟数据作为gameId,但我想要单击的特定游戏的ID。下面是我正在使用的JSON的示例,然后在下面是我的使用虚拟数据的upvote函数。
"_id" : ObjectId("5b7b67247a3b516f8cb0c7d9"),
"ID" : "2cd057a6-ec9c-469c-b2ba-3fe50894d135",
"HomeTeam" : "Arizona Diamondbacks",
"AwayTeam" : "Los Angeles Angels",
"Sport" : 0,
"MatchTime" : "2018-08-22T01:40:00",
"Details" : "Los Angeles Angels at Arizona Diamondbacks",
"HomePitcher" : "Patrick Corbin",
"AwayPitcher" : "Felix Pena",
"HomeROT" : "930",
"AwayROT" : "929",
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(gameId);
} else {
return res.sendStatus(400);
}
});
gameId.then(function(game){
if(game){
} else {
return res.sendStatus(400);
}
});
},