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

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -