how to add new array in body.history.. nodejs

夙愿已清 提交于 2019-12-24 08:13:14

问题


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")
    },

回答1:


for Add new array Use Push Below Suggested Code

  var add= new JobHistory({ changetype: 'eesss', details: delta });

       req.body.history.push(add); 


来源:https://stackoverflow.com/questions/41533714/how-to-add-new-array-in-body-history-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!