Skip to content

Instantly share code, notes, and snippets.

@Raduuu
Last active June 2, 2020 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raduuu/d74b509855c9e8c174b468605f8f7c90 to your computer and use it in GitHub Desktop.
Save Raduuu/d74b509855c9e8c174b468605f8f7c90 to your computer and use it in GitHub Desktop.
import mongoose from 'mongoose'
const productSchema = new mongoose.Schema(
{
name: {
type: String,
required: true,
trim: true,
maxlength: 50,
text: true
},
description: {
type: String,
required: true,
trim: true,
maxlength: 100
},
quantity: {
type: Number,
required: true,
trim: true,
maxlength: 3
},
price: {
type: Number,
required: true,
trim: true,
maxlength: 3
},
},
{ timestamps: true }
)
productSchema.index({ category: 1, name: 1 }, { unique: true })
export const Product = mongoose.model('product', productSchema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment