1const fruitSchema = new mongoose.Schema ({
2 name: {
3 type: String
4 },
5 rating: {
6 type: Number,
7 min: 1,
8 max: 10
9 },
10 review: String
11});
1 var mongoose = require('mongoose');
2 var Schema = mongoose.Schema;
3
4 var blogSchema = new Schema({
5 title: String, // String is shorthand for {type: String}
6 author: String,
7 body: String,
8 comments: [{ body: String, date: Date }],
9 date: { type: Date, default: Date.now },
10 hidden: Boolean,
11 meta: {
12 votes: Number,
13 favs: Number
14 }
15 });
1import mongoose from 'mongoose'
2
3const { Schema } = mongoose
4
5const value = {
6 type: String,
7 required: true,
8 trim: true,
9 unique: false
10}
11
12const UserSchema = new Schema({
13 fname: value,
14 lname: value,
15 email: {
16 type: String,
17 required: true,
18 trim: true,
19 unique: true
20 }
21}, {
22 timestamps: true,
23 get: v => v.toDateString()
24})
25
26const User = mongoose.model('User', UserSchema)
27export default User
28