Array of objects passes validation but doesn't update collection

折月煮酒 提交于 2019-12-12 04:15:43

问题


My update method is passing the simple-schema validation test however it isn't updating my collection. I'm updating an array of objects.

Example: array

var arrayTest = [ 
  { 
    company: 'sdsd',
    uniqueId: 1500431892902,
    title: '',
    description: '',
    startDateMonth: '',
    startDateYear: '',
    endDateMonth: '',
    endDateYear: '',
    isCurrent: false,
    isDisabled: false,
  } 
];

Validate: Array

new SimpleSchema({
  company: { type: String, optional: true },
  uniqueId: { type: Number, optional: true },
  title: { type: String, optional: true },
  description: { type: String, optional: true },
  startDateMonth: { type: String, optional: true },
  startDateYear: { type: String, optional: true },
  endDateMonth: { type: String, optional: true },
  endDateYear: { type: String, optional: true },
  isCurrent: { type: Boolean, optional: true },
  isDisabled: { type: Boolean, optional: true }
}).validate(
  arrayTest
);

Update: Collection

ProfileCandidate.update({
  _id: "BoDb4Zztq7n3evTqG"
}, {
  $set: {
    careerHistoryPositions: arrayTest
  }
}, (error, result) => {
  if (error) {
    console.log("error: ", "error");
  }
  if (result) {
    console.log("result", result);
  }
});

The update appears to work however no data goes into the schema.

来源:https://stackoverflow.com/questions/45180249/array-of-objects-passes-validation-but-doesnt-update-collection

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