Mongoose populate with array of objects containing ref -


i have mongoose schema array lists of objects consist of reference collection , nested array of numbers:

var schema, exports, mongoose, schema;  mongoose = require("mongoose");  schema = mongoose.schema;  schema = new schema({   name: {     type: string,     required: true,     unique: true,     trim: true   },   lists: [     {       list: {         type: schema.objectid,         require: true,         ref: "list"       },       allocations: [         {           type: number,           required: true         }       ]     }   ],   createdat: {     type: date,     "default": date.now   },   updatedat: {     type: date   } });  exports = module.exports = mongoose.model("portfolio", schema); 

however, cannot populate work expected without getting typeerror: cannot read property 'ref' of undefined. i've tried populate('list') , populate('lists list') i'm either not calling things correctly or schema isn't formed correctly. don't have problem if reference lists themselves:

lists: [     {         type: schema.objectid,         require: true,         ref: "list"     }   ] 

but want have allocations array alongside each list. need behavior want?

i found answer: populate('lists.list') works. question: mongoose populate within object?


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -