【发布时间】:2020-02-26 00:58:00
【问题描述】:
我正在将 AngularJS 应用程序转换为 Angular 7,它们共享一个后端 API。我正在提交相同的数据,并且记录正确,但是在尝试保存记录时,我在后端返回了一个关于未知修饰符 $pushAll 的错误。
我的控制器代码:
Volunteer
.findById(volunteerId)
.select('shifts')
.exec(function(err, volunteer) {
var thisShift;
var response = {
status : 200,
message : {}
};
if (err) {
console.log("Error finding volunteer request");
response.status = 500;
response.message = err;
} else if(!volunteer) {
console.log("Volunteer request not found", volunteerId);
response.status = 404;
response.message = {
"message" : "Volunteer request not found " + volunteerId
};
} else {
// Get the shift
thisShift = volunteer.shifts.id(shiftId);
console.log("SHIFT BEFORE UPDATE", JSON.stringify(thisShift));
// If the shift doesn't exist Mongoose returns null
if (!thisShift) {
response.status = 404;
response.message = {
"message" : "Shift not found " + shiftId
};
}
}
if (response.status !== 200) {
res
.status(response.status)
.json(response.message);
} else {
thisShift.volleyteers.push({
fullname: user.name,
phone: user.phone,
email: user.username
});
console.log("thisShift to be saved", JSON.stringify(thisShift));
volunteer.save(function(err, volunteerUpdated) {
if (err) {
console.log("ERROR",err);
res
.status(500)
.json(err);
} else {
console.log("SUCCESS!");
res
.status(204)
.json({message: "Thank you for volunteering! You can see where you need to on your profile page or someone will contact you."});
}
});
}
});
};
我得到的错误以及后端的 console.logged 内容是:
我正在使用:
- 节点 11.13.0
- MongoDB服务器版本:4.0.8
- “猫鼬”:“^4.9.6”
如何让这个错误消失,以便保存更新的记录?
【问题讨论】: