Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. var Order = new Schema({
  2. items: [{
  3. product: {
  4. type: Schema.Types.ObjectId,
  5. ref: "Product",
  6. }
  7. ...
  8. }]
  9. });
  10.  
  11.  
  12. var Product = new Schema({
  13. categories: [{
  14. type: Schema.Types.ObjectId,
  15. ref: "Category",
  16. }]
  17. });
  18.  
  19. Order.findById(id).populate('items.product').exec(function(err, doc) {
  20. var opts = {
  21. path: 'items.product.categories'
  22. };
  23.  
  24. console.log(doc.items[0].product.categories) // [ 524f035de9d6178e460001a2, 524f0965e9d6178e460001b6 ] - these docs are in the database under the Category collection
  25.  
  26. Order.populate(doc, opts, function(err, doc) {
  27. // Returns order with category array blank for each product
  28. console.log(doc.items[0].product.categories // []
  29. });
  30. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement