我试图找到对另一个架构的引用并更新同级字段。具体来说,我试图根据特定的“调查”ObjectId操纵下面的hasResponded字段。使用猫鼬findbyid和更新同级
我的模式是这样的:
var userSchema = new mongoose.Schema({
// some other stuff
surveys: [{
survey: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Survey'
},
hasResponded: {
type: Boolean,
default: false
}
}]
});
所以你基本上要求如何找到所有在他们的调查数组中有特定调查ID的用户? (然后更新其对应的hasResponded字段?) – Protostome 2014-10-29 13:09:55
在这种情况下,只有一个用户,但我也有兴趣为所有具有特定调查ID的用户更新类似的字段。 – 2014-10-29 13:17:19
看到我的答案.... – Protostome 2014-10-29 13:20:21