Search code examples
node.jsmeteorsimple-schema

meteor collections simpleschema, allowedvalues for array?


When i have created a schema:

  permissions: {
    type:[String],
    allowedValues: [
      'admin', 'normal',
    ],
  },

do the allowedValues checks apply for the elements inside the array?


Solution

  • According to this feature request you would use this:

    permissions: {
        type:[String]
    },
    permissions.$: {
        type: String,
        allowedValues: [
            'admin', 'normal'
        ],
    }
    

    You will need to have a way to ensure that duplicate values don't get pushed onto the array.