【发布时间】:2014-03-27 05:47:06
【问题描述】:
我有一个承诺,我将使用 mongoose 进行数据库操作。使用 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()应该做什么?
标签: node.js mongodb mongoose promise