I’ve been trying to come up with ideas to build the below schema from a maintainability standpoint, however am not getting the right result.
Background:
I have to build about 30 different collections, inclusive of schemas
Some fields of the 30 schemas are common accross some collections
What’s required:
Write schemas for all the 30 of them, as simple as possible.
An approach to maintain them (eg., should a new field be added, how to have miminal changes done in the code to accept the new changes)
What’s been tried:
I’m using autoforms, collection2 and simple-schema for this.
Approach 1:
Tried to build a huge schema repo where in all the single level schema and multilevel schema are present. This makes it easy to get the final schema ready. All the final schema requires is to pick up and build on the single level schema.
Example: I can’t use the actual code I’m working on, so here’s an analogy.
What the DB collection should look like:
multilevel {
"name" : "DummyPotato"
"options" : {
"opton1":"anOption",
"option2": "anotherOption"
}
"Misc":"someMiscValue"
}
collection.js contains this:
nameSchema = new SimpleSchema ({ type: String, regEx: <hassomeregex> });
option1Schema = new SimpleSchema ({ type: String });
option2Schema = new SimpleSchema ({ type: String });
miscSchema = new SimpleSchema (type: String, allowedValues: ['a','b','c'] });
optionSchema = new SimpleSchema ([option1Schema, option2Schema]);
multilevel = new SimpleSchema ([nameSchema, optionSchema, miscSchema])
I have a simple form for the above with submit button. When I submit, howeve, the result is persisted as a flat document instead of a nested document. Is there a different approach for this?
{
"name" : "DummyPotato"
"options"
"opton1":"anOption",
"option2": "anotherOption"
"Misc":"someMiscValue"
}
I’ve taken a look at other means mentioned in simple-schema documentation, but am unable to figure out how to use them . (‘pick’ option). Any ideas?
Approach 2
This is to embed everything into a single schema. It works fine, but I’m not conviced when it comes to reuse and maintainace.
Example:
multilevelSchema = new SimpleSchema ({
"Multilevel.name" : { type: String, regEx: <hassomeregex> },
"Multilevel.options.option1" : { type: String },
"Multilevel.options.option2" : { type: String },
"Multilevel.misc" : {type: String, allowedValues: ['a','b','c'] }
});
The above generates the document as it should - nested.