mongodb - Reference is not checking exact type -


i defined model mentioned below:

var questionschema = new schema({ askedby: {type:objectid, ref:'user'}, relatedcourses: [     {type: objectid, ref:'course'} ] }) module.exports = mongoose.model('question', questionschema, 'questions') 

(because of bug) @ time of saving/creating new document of type question, relatedcourses field assigned array of object ids other 'course', , mongoose didn't produce error, , saved document.

it took sometime dig , find error.

my question is, why mongoose not checking exact schema type? need of mentioning 'course' in ref field when objectid sufficient?

i found mongoose-id-validator, doing required type validation.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -