本文介绍了如何在body.history..nodejs中添加新数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有作业历史记录模式,我想将其他数据推送到历史记录"数组中..该怎么做..因为它更新了我的旧作业历史记录,所以我想在作业历史记录中添加一个新数组.
i have Job history schema i want to push other data in History array..how do this..because its update my old Job history i want new one array add in Job history.
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")
},
推荐答案
用于添加新数组使用推下面的建议代码
for Add new array Use PushBelow Suggested Code
var add= new JobHistory({ changetype: 'eesss', details: delta });
req.body.history.push(add);
这篇关于如何在body.history..nodejs中添加新数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!