I have two schemas, defined like so (extra fields ommitted):
Transaction = new Schema({
'lineItems' : {type: [LineItem]},
'orderNumber' : { type: Number}
});
LineItem = new Schema({
'product' : {type: Schema.ObjectId,ref: 'Product'}
});
I then have a query, which is attempting to populate the lineItems.product documents:
var qry = app.Transaction.findOne({orderNumber : req.params.orderNumber})
.populate('lineItems.product')
.run(function(err,transaction) {
res.render('store/receipt', { transaction : transaction})
})
This is throwing the following error when it tries to populate lineItems.product:
[ERROR] TypeError
TypeError: Cannot call method 'path' of undefined
at /home/tyler/projects/prescribed/node_modules/mongoose/lib/model.js:233:44
at /home/tyler/projects/prescribed/node_modules/mongoose/lib/model.js:239:14
at Array.forEach (native)
When I debugged into it, I found that the subschema on line 233 is undefined, however I'm not sure how this could be?