问题是你使用了错误的语法更新方法。你应该使用这个方法的语法,假设scores
是一个文档。
return scores.updateQ({
$set: { "partId": partId, "activityId": activityId},
$unset: { topicType: '', topicId: '', courseId: ''}
},
{ strict: false });
另外,在 Mongoose 中,它使用$set
默认情况下,所以这应该是等效的:
return scores.updateQ({
partId: partId,
activityId: activityId,
$unset: { topicType: '', topicId: '', courseId: ''}
},
{ strict: false });
EDIT:
我的假设是scores
是一个文档(模型的一个实例):
var schema = new Schema({});
var Scores = mongoose.model('Scores', schema);
var scores = new Scores({});
Both Scores.update
and scores.update
存在,但语法不同,这可能是导致错误的原因。区别如下:
// Generic update
Scores.update({ _id: id }, { prop: 'value' }, callback);
// Designed to update scores specifically
scores.update({ prop: 'value' }, callback);
NOTE:
如果这些假设不正确,请在您的答案中包含更多背景信息,例如您是如何到达那里的。