Good day dear colleagues. Please tell me why this option of nesting in the mungus scheme does not work and how to make it correctly?

mongoose.schema('media', { name : String, sourceName : String, altText : String, detail : {album : String, category : String, type : String}, date : Date }); var model = mongoose.model('Media', media); mediaModel = new Media_Module.mediaModelScheme({ name : 'test', sourceName : 'test1', altText : 'test2', detail : {album : 'test3' ,category : 'test4' ,type : 'test5'}, date : Date.now() }); 

When saving a document, I get the following error: Cast to String failed for value "[object Object]" at path "detail"

I know that you can do this, but I would like to directly write the nested object:

  /* nested scheme */ this.mediaDetailScheme = this.db.getScheme('detail', { album : String, category: String, type : String }); /* primary scheme */ this.mediaModelScheme = this.db.getModel('media', { name : String, sourceName : String, altText : String, detail : [this.mediaDetailScheme], date : Date }); 

    1 answer 1

    Reason: type - reserved word for mongoose.

    detail: {type: String} equivalent to detail: String

    Solution: Use mytype , _type and other keys.

    Links: http://mongoosejs.com/docs/guide.html (en)