Could I use dynamic simple-schema on one Collection?


#1
import {Mongo} from 'meteor/mongo';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';

export const Client = new Mongo.Collection("client");

// Optional is ture
Schema1 = new SimpleSchema({
    name: {
        type: String,
        label: 'Name',
        optional: true,
    }
......
});
---------
// Required
Schema2 = new SimpleSchema({
    name: {
        type: String,
        label: 'Name',
    }
......
});

// Check setting collection
.....
if(getSetting.optional === true){
   Client.attachSchema(Schema1)
}else{
   Client.attachSchema(Schema2)
}

Please help me.


#2

Check out attaching of multiple schemas, that might be the better solution


#3

I also see that you are using atmosphere version of SimpleSchema.

There is an npm package called simpl-schema by aldeed with up to date features.

I recommend you to take a look at the following link change log


#4

Thanks, I will try :smile: