I want to validate some inner elements of an object against schemas that are members of a larger schema before posting that object on the model correspondent to that larger schema.
Someone already asked this question and this answer has something similar on the second option proposed:
var p = new People({
name: 'you',
age: 3
});
p.validate(function(err) {
if (err)
console.log(err);
else
console.log('pass validate');
});
The problem is that before doing the validation one has to create a new model with var People = mongoose.model('People', peopleSchema);
.
Does this mean in this case that a new collection 'People'
will be stored in the MongoDB database?
Is the act of calling mongoose.model('People', peopleSchema);
altering the database in any way?
If so, is there a way to do this validation without creating a new collection, in this case 'People'
?
The schema I want to validate will be stored as a component of another document already in the database and I don't want to pollute the database with unused collections.