【发布时间】:2016-07-08 23:23:08
【问题描述】:
我有一个删除团队和加入该特定团队的所有请求的路由,它嵌套在 UserProfiles 的 JoinTeamRequests 数组中。这个想法是在删除该团队后删除该团队的所有邀请痕迹。我正在使用 MEAN 堆栈。我还是新手,所以任何其他建议或建议都会很棒。
这是我的路线:
//Remove a specific team
.delete (function (req, res) {
//Delete the team - works
TeamProfile.remove({
_id : req.body.TeamID
}, function (err, draft) {
if (err)
res.send(err);
});
UserProfile.find(
function (err, allProfiles) {
for (var i in allProfiles) {
for (var x in allProfiles[i].JoinTeamRequests) {
if (allProfiles[i].JoinTeamRequests[x].TeamID == req.body.TeamID) {
allProfiles[i].JoinTeamRequests.splice(x, 1);
console.log(allProfiles[i]); //logs the correct profile and is modified
}
}
}
}).exec(function (err, allProfiles) {
allProfiles.save(function (err) { //error thrown here
if (err)
res.send(err);
res.json({
message : 'Team Successfully deleted'
});
});
});
});
但是,我收到一个错误:TypeError: allProfiles.save is not a function。
为什么会抛出这个错误?
【问题讨论】:
标签: node.js mongodb mongoose mean-stack