javascript - Mongoose 3.6+ population of populated fields -
according 3.6 release notes should able populate categories in order.items.product docs no go. here's schemas:
var order = new schema({ items: [{ product: { type: schema.types.objectid, ref: "product", } ... }] }); var product = new schema({ categories: [{ type: schema.types.objectid, ref: "category", }] });
my query (one of many - 've tried few combos - seems suggested)
order.findbyid(id).populate('items.product').exec(function(err, doc) { var opts = { path: 'items.product.categories' }; console.log(doc.items[0].product.categories) // [ 524f035de9d6178e460001a2, 524f0965e9d6178e460001b6 ] - these docs in database under category collection order.populate(doc, opts, function(err, doc) { // returns order category array blank each product console.log(doc.items[0].product.categories // [] }); });
it looks accidentally typed order
again in sub-population call.
the second populate call should like:
category.populate(doc, opts, function(err, doc) {...
instead of
order.populate(doc, opts, function(err, doc) {...
you're telling mongoose populate each product's categories
array element order
instead of category
.
Comments
Post a Comment