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
Post a Comment