Update array of objects leads to blank array

59 Views Asked by At

Please tell me what I'm missing here. When I update the Array of objects my collection updates with an empty array. I'm using meteor-collection2-core and node-simple-schema.

Path: Method

testArray = [{
    "institution": "Swinburn",
    "uniqueId": 1501036480813,
    "qualification": "Bachelor of Commerce",
    "completed": "2017"
}]

ProfileCandidate.update('Ntzj6kE8qZsvSPMEP', {$set: {educationQualifications: testArray}});

Path: Collection

export const ProfileCandidate = new Mongo.Collection('profileCandidate');

const ProfileCandidateSchema = new SimpleSchema({
  userId: {
    type: String,
    regEx: SimpleSchema.RegEx.Id
  },
  educationQualifications: { type: Array, optional: true },
  'educationQualifications.$': { type: Object, optional: true },
  'educationQualifications.$.uniqueId': { type: Number, optional: true },
  'educationQualifications.$.institution': { type: String, optional: true },
  'educationQualifications.$.qualification': { type: String, optional: true },
  'educationQualifications.$.completed': { type: String, optional: true }
});

ProfileCandidate.attachSchema(ProfileCandidateSchema);
1

There are 1 best solutions below

1
bordalix On

In your method, try this:

ProfileCandidate.update({userId: 'Ntzj6kE8qZsvSPMEP'}, {$set: {educationQualifications: testArray}});