Mongoose: Embed a model as array of another model -
i have menu items have roles make links them restrictive. 1. rolemodel.js const menuroleschema = new mongoose.schema ({ name: { type: string, unique: true}, { _id: true }); exports.menurolemodel = mongoose.model('menurolemodel', menuroleschema, 'menu_role'); 2. menuitemmodel.js const menuitemschema = new mongoose.schema({ ...... roles: [ { type: menurolemodel } ] }); 3. menuitemseed.js const data = [ { ..... "roles": [{"name": "rolea"}], }, { .... "roles": [{"name": "rolea"}, {"name": "roleb"}], } ] my menuitemmodel not populating in database, , naturally no errors provided. how structure schema seed data laid out roles works? thanks this did trick me: 1. rolemodel.js (1)export const menuroleschema = new mongoose....