Skip to content

Instantly share code, notes, and snippets.

@MarcoAlejandro
Created December 26, 2018 08:22
Show Gist options
  • Save MarcoAlejandro/a1c9d7eb61062a37bd85c59b9e8cbbaa to your computer and use it in GitHub Desktop.
Save MarcoAlejandro/a1c9d7eb61062a37bd85c59b9e8cbbaa to your computer and use it in GitHub Desktop.
Mongoose model recipe.
//https://mongoosejs.com/docs/guide.html
const mongoose = require('mongoose')
const Schema = mongoose.Schema;
var commentSchema = new Schema({
rating: {
type: Number,
min: 1,
max: 5,
required: true
},
comment: {
type: String,
required: true
},
author: {
type: String,
required: true
}
},{
timestamps: true
});
const dishSchema = new Schema({
name: {
type: String,
required: true,
unique: true
},
description: {
type: String,
required: true
},
image: {
type: String,
required: true
},
category: {
type: String,
required: true
},
label: {
type: String,
default: ''
},
price: {
type: Currency,
required: true,
min: 0
},
featured: {
type: Boolean,
default:false
},
comments:[commentSchema]
}, {
timestamps: true
});
var Dishes = mongoose.model('Dish', dishSchema)
module.exports = Dishes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment