SHARE
TWEET

Untitled

a guest Nov 15th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var clientSchema = new Schema({
  2.     phone: String,
  3.     email: String
  4.     },
  5. );
  6.  
  7. var menuSchema = new Schema({
  8.     itemName: String,
  9.     itemPrice: Number,
  10. });
  11.  
  12.  
  13. var transactionSchema = new Schema ({
  14.     createdBy: { type: Schema.ObjectId, ref: 'Client'},
  15.     items: [{ type: Schema.ObjectId, ref: 'Menu' }],
  16. });
  17.  
  18. var Menu = mongoose.model('Menu', menuSchema);
  19. var Client = mongoose.model('Client', clientSchema);
  20. var Transaction = mongoose.model('Transaction', transactionSchema);
  21.    
  22. {
  23.     "_id": "5a0bde94f4434c0a604341d2",
  24.     "createdBy": {
  25.         "_id": "5a0a8a3f9c348f0998ba8c2c",
  26.         "phone": "1234567890",
  27.         "email": "some@thing.com"
  28.     },
  29.     "__v": 0,
  30.     "items": [{ Many Menu objects }]
  31. }
  32.    
  33. {
  34.     "_id": "5a0bde94f4434c0a604341d2",
  35.     "createdBy": "5a0a8a3f9c348f0998ba8c2c",
  36.     "__v": 0,
  37.     "items": [Array of ObjectIds]
  38. }
  39.    
  40. var transactionSchema = new Schema ({
  41.     createdBy: { type: Schema.ObjectId, ref: 'Client'},
  42.     items: [menuSchema], // Sub Doc
  43. });
  44.    
  45. var transactionSchema = new Schema ({
  46.     createdBy: { type: Schema.ObjectId, ref: 'Client'},
  47.     items: [{
  48.       name: {type: String},
  49.       price: {type: Number}
  50.     }]
  51. });
RAW Paste Data
Top