I am trying to take advantage of the fact that MongoDB as a document database does not have a schema, which allows me to store documents with slightly different properties.
The scenario is that I want to have a collection, eg. Pets, that lists all my pets which share name and birthdate. However, one is a dog, the other a bird and the third a lizard. Those different species have different sub-properties (and no hate about my loose definition of species, please )
The problem is to have the trifecta of autoform, simpleschema and collection2 handle this properly, which means form creation and validation.
In my Schema.Pet
I made up the new type Schema
to denote that any of the allowedValues
is a proper schema. Unfortunately this doesn’t work.
Does anybody have an idea how to handle this?
Schema.Reptile = new SimpleSchema({
length: {
type: Number;
},
venomous: {
type: Boolean;
}
});
Schema.Mammal = new SimpleSchema({
legs:{
type: Number,
allowedValues: [2,4],
}
});
Schema.Bird = new SimpleSchema({
carnivorous: {
type: Boolean;
}
});
Schemas.Pet = new SimpleSchema({
name: {
type: String,
},
kindof: {
type: Schema,
allowedValues: [ Schema.Reptile, Schema.Mammal, Schema.Bird ]
},
});
Pets.attachSchema(Pet);
I also filed a github issue