1
var WorkstationSchema = new Schema({
tag: { type : String },
address : { type : String , unique : true, required : true },
status: { type : String , required : true },
});
var ProblemSchema = new Schema({
type: { type: Number, default: 0 },
status: { type: Number, default: 0 },
dateCreated: { type: String, trim: true, default: '' },
workstation: {type: Schema.ObjectId, ref: 'Workstation'},
});
conditions = {type: problemType, status: 0, 'workstation.address': remote64};
update = {status: 1};
ProblemSchema.findOneAndUpdate(conditions, update, options).populate('workstation', 'address').exec(function (err, problem) {
if(err){
//do something
} else {
console.log(problem);
}
});
这些是我的实体,我需要找到一个问题,该工作站具有此地址并更新问题状态。猫鼬:FindOneAndUpdate()与来自现场参考的查询
我该怎么做?
感谢您的帮助,但此解决方案不起作用。因为forEach不是一个函数。 TypeError:ProblemSchema.find(...)。populate(...)。snapshot(...)。forEach不是函数 –
可以尝试更新的答案@FabrícioLélis –
现在,它的工作原理!谢谢,但还有一个问题。如果我有两个以上的问题,但我只想编辑一个。我能怎么做? –