【发布时间】:2021-09-26 21:48:24
【问题描述】:
我从两个异步调用中获得了两个对象 runnningGame 和 runningGameTime。对象是:
{
numberOfBets: 0,
totalAmountCollected: 0,
amountDistributed: 0,
finished: false,
_id: 60f52b621bcef84190024cfd,
gameId: 60f52b621bcef84190024cfb,
allPlayerBettedBetId: [],
createdAt: 2021-07-19T07:36:02.240Z,
updatedAt: 2021-07-19T07:36:02.240Z,
__v: 0
}
{
startTime: 2021-07-19T07:36:02.235Z,
_id: 60f52b621bcef84190024cfb,
gameType: 'Slow Parity',
endTime: 2021-07-19T07:39:02.235Z,
createdAt: 2021-07-19T07:36:02.237Z,
updatedAt: 2021-07-19T07:36:02.237Z,
__v: 0
}
我正在做这些操作
try {
let runningGame = await model.findOne({ finished: false });
const runnigGameTime = await Game.findById(runningGame.gameId);
const finishedGameDetails = await model.finishedGames();
runningGame.endTime = finishedGameDetails.endTime;
console.log(runningGame);
res.send();
// res.send({runningGameDetails:{endTime:runnigGameTime.endTime,startTime:runnigGameTime.startTime,runningGame},finishedGameDetails});
}
catch (error)
{
console.log(error);
res.status(400).send({ error });
}
但是在第 4 行的 try 块中没有执行我得到相同的 runningGame 对象,即使在将 endTime 添加到它之后也是如此。这里有什么问题?????????
【问题讨论】:
-
请提供更多信息:您的
model和model.finishedGames是什么? -
不保存命令,为什么不是同一个对象?
标签: javascript object asynchronous mongoose