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 –
現在,它的工作原理!謝謝,但還有一個問題。如果我有兩個以上的問題,但我只想編輯一個。我能怎麼做? –