我遇到了以下问题。我正在创建项目管理应用程序,当我删除里程碑时,我想从 ReportEntry 文档中取消设置其 ID,并将里程碑的标题添加到 ReportEntry 的另一个属性中。我有以下代码:
MilestoneSchema.pre('remove', function(next) {
this.model('ReportEntry').update(
{milestone: this._id},
{$unset: {milestone: ""}},
{$set: {removedMilestone: this.title}},
{multi: true},
next
);
});
这不起作用,它会在 node.js 控制台中引发错误:writeConcern 需要在 updateWithWriteCommands(路径)处回调。怎么了?谢谢:)
最佳答案
Mongoose 的 Model#update方法只接受 4 个参数,回调是最后一个。您已及格 5 分。
试试这个:
this.model('ReportEntry').update(
{milestone: this._id},
{
$unset: {milestone: ""},
$set: {removedMilestone: this.title},
},
{multi: true},
next
);
关于javascript - 写关注需要回调 - Mongoose + Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34122950/