Mdg:validated-method/aldeed:simple-schema array validation


#1
            Memberships.upsert({userId: this.userId}, { 
                $push: {portalAccess: newInfo.portalAccess} 
            });

The code above is from my ValidatedMethod, where I am trying to push a new array element (i.e. portalAccess) into the Memberships schema, which is like this:

Memberships.schema = new SimpleSchema({
    userId:{
        type: String,
        regEx: SimpleSchema.RegEx.Id
    },

    portalAccess:{
        type:[Object]
    },

..more portalAccess.$.xyz definitions here

However, on running validate before I do run.call , I get

exception: Portal access must be an array [validation-error]

My question is why? Shouldn’t the $push call just push the new element into the array?


#2

Try specifying it as a type Array, instead of an array of objects:

const schema = new SimpleSchema({
  addresses: {
    type: Array,
    minCount: 1,
    maxCount: 4
  },
  'addresses.$': Object,
  'addresses.$.street': String,
  'addresses.$.city': String,
})

If I’m not mistaking, it used to be [Object], but the latest npm versions wants it like this.