Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Order = new Schema({
- items: [{
- product: {
- type: Schema.Types.ObjectId,
- ref: "Product",
- }
- ...
- }]
- });
- var Product = new Schema({
- categories: [{
- type: Schema.Types.ObjectId,
- ref: "Category",
- }]
- });
- 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 are in the database under the Category collection
- Order.populate(doc, opts, function(err, doc) {
- // Returns order with category array blank for each product
- console.log(doc.items[0].product.categories // []
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement