我想在使用 mongodb 数据库中的 find() 后执行函数。
router.post('/', (req, res) => {
Game.find({'homeTeamName': req.body.homeTeamName})
.then(games => res.json(games))
.catch(err =>
res.status(404).json('no games')
)
})
是否可以在 .then 中执行函数或者只是将游戏保存在某处。 我还有一个问题,我可以做这样的事情来查找所有客场比赛吗?
Game.find({'homeTeamName': req.body.homeTeamName} || {'awayTeamName': req.body.homeTeamName})
最佳答案
做这样的事情
router.post('/', (req, res) => {
Game.find({$or:[{ "homeTeamName": req.body.homeTeamName }, { "awayTeamName": req.body.homeTeamName }]})
.then((games) => {
executeYourFunction();
res.json(games)
})
.catch(err =>
res.status(404).json('no games')
)
})
executeYourFunction(){
console.log("success")
}
关于javascript - 如何执行find中的函数或将数据保存在变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51677362/