我有作业历史模式我想在历史数组中推送其他数据..如何做到这一点...因为它更新我的旧作业历史记录我希望在作业历史记录中添加新的数组。
var JobChangeHistorySchema = new Schema({
datetime: { type: Date, default: Date.now },
changetype: { type: String, default:''},
details: { type: String, default:''},
updated_by: { type: String, default:''}
});
import JobHistory from './job_models/job_changehistory.model';
req.body.history = new JobHistory({ changetype: 'eesss', details: delta });
ss.findOneAndUpdate({ _id: req.params.id }, req.body , { new: true, upsert: true, setDefaultsOnInsert: true, runValidators: true }).exec().then(function (Job)
"history" : {
"_id" : ObjectId("58724445554a2515404de8ed"),
"updated_by" : "",
"details" : "",
"changetype" : "eesss",
"datetime" : ISODate("2017-01-08T13:53:09.319Z")
},
答案 0 :(得分:0)
添加新阵列使用推送 建议代码
var add= new JobHistory({ changetype: 'eesss', details: delta });
req.body.history.push(add);