Meteor + collection2: how to verify subkeys in a blackbox key

44 views Asked by At

I need to store a hash of uuids under an specific object key, something like:

{
   myHash: {
      "20948-d32d2-d2d2..": "some value 1",
      "20778-d7322-j5j5..": "some value 2",
      ...
   }
   ...
}

For that I've used the blackbox key of meteor-simple-schema:

myHash: {
    type: Object,
    blackbox: true,
},

That's working: the hash keys are saving to the db.

Problems is, I can't figure out how to add schema verifications to the value of the blackbox keys: "some value 1" and "some value 2".

For example, assuming I need to enforce a max length. How would I implement it?

1

There are 1 answers

0
kkkkkkk On

You could use custom function to do the validation here:

  myHash: {
    type: Object,
    optional: true,
    blackbox: true,
    custom() {
      const value = this.value;
      if(/* value is not validated */) {
        return 'notAllowed';
      }

    },
  },