Order.findById(orderId)
.populate(
[{
path: 'prescription'
}]
)
// .lean()
.then(order => {
theOrder = order;
let checkLogInfo = {
orderId: order._id,
prescription: order.prescription.toJSON(),
checkResult: order.checkResult
}
let checkLog = new CheckLog(checkLogInfo);
return checkLog.save();
})
.then(newCheckLog => {
theNewCheckLog = newCheckLog;
return Prescription.update({_id: theOrder.prescription._id}, {prescriptionInformation: req.body.prescriptionInformation});
})
.then(() => {
console.info(theOrder.checkLog);
theOrder.checkLog.push(theNewCheckLog._id);
console.info(theOrder.checkLog);
theOrder.checkResult = null;
return theOrder.save();
})
.then(() => {
return res.send({code: '400000', messageInfo: ['The update was successful.']});
})
.catch(err => next(err));
- 由于 theOrder.checkLog.push(theNewCheckLog._id); 这句,在mongoose保存时报错 MongoError: Unknown modifier: $pushAll
- 原因:版本冲突
- 解决办法:在新建schema的时候加上{usePushEach: true}配置就可以了
let OrderSchema = new Schema({
doctor: {
type: Schema.ObjectId,
ref: 'user'
},
pharmacist: {
type: Schema.ObjectId,
ref: 'user'
}
}, {timestamps: {createdAt: 'created', updatedAt: 'updated'}, usePushEach: true});