Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var clientSchema = new Schema({
- phone: String,
- email: String
- },
- );
- var menuSchema = new Schema({
- itemName: String,
- itemPrice: Number,
- });
- var transactionSchema = new Schema ({
- createdBy: { type: Schema.ObjectId, ref: 'Client'},
- items: [{ type: Schema.ObjectId, ref: 'Menu' }],
- });
- var Menu = mongoose.model('Menu', menuSchema);
- var Client = mongoose.model('Client', clientSchema);
- var Transaction = mongoose.model('Transaction', transactionSchema);
- {
- "_id": "5a0bde94f4434c0a604341d2",
- "createdBy": {
- "_id": "5a0a8a3f9c348f0998ba8c2c",
- "phone": "1234567890",
- "email": "some@thing.com"
- },
- "__v": 0,
- "items": [{ Many Menu objects }]
- }
- {
- "_id": "5a0bde94f4434c0a604341d2",
- "createdBy": "5a0a8a3f9c348f0998ba8c2c",
- "__v": 0,
- "items": [Array of ObjectIds]
- }
- var transactionSchema = new Schema ({
- createdBy: { type: Schema.ObjectId, ref: 'Client'},
- items: [menuSchema], // Sub Doc
- });
- var transactionSchema = new Schema ({
- createdBy: { type: Schema.ObjectId, ref: 'Client'},
- items: [{
- name: {type: String},
- price: {type: Number}
- }]
- });
Add Comment
Please, Sign In to add comment