0
我有一個承諾,我正在使用貓鼬做數據庫操作。使用mpromise庫,我正在使用teamMatch
並使用它來更新Team
文檔。但是,該程序不會在我更新Team
(開始於var getTeamPromise)之後執行任何操作。嵌套承諾與貓鼬
如何更改此代碼以便我可以更輕鬆地執行上述操作?
saveTeamMatch.then(
function saveTeamMatchToTeam(teamMatch) {
console.log('TEAM_MATCH in SAVE to TEAM', teamMatch); //works
// when a team is gotten and a teamMatch is made and saved
// save the teamMatch to the team
var getTeamPromise = Team.findOneAndUpdate({ id:1540 }, { $push:{ matches:teamMatch } }).exec()
.then(
function successfullySaveTeamMatchToTeam(team) {
console.log('TEAM in SUCCESSFUL SAVE', team);
getTeamPromise.resolve();
},
function failToUpdateTeam(err) {
console.error(err);
getTeamPromise.resolve();
}
)
.resolve(
function endFindMatchPromise() {
saveTeamMatch.end();
}
);
},
function failToSaveTeamMatch(err) {
console.error(err);
saveTeamMatch.end();
}
);
什麼'.resolve ()'應該這樣做? – Bergi