1const mongoose = require('mongoose');
2
3const UserSchema = new mongoose.Schema({
4 name: {
5 type: String,
6 required: true
7 }
8}, {
9 timestamps: true
10})
11
12const User = mongoose.model('User', UserSchema);
13
14module.exports = User;
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 });
1// Define schema
2var Schema = mongoose.Schema;
3
4var SomeModelSchema = new Schema({
5 a_string: String,
6 a_date: Date
7});
8
9// Compile model from schema
10var SomeModel = mongoose.model('SomeModel', SomeModelSchema );
1const mongoose = require("mongoose");
2
3const todoSchema = mongoose.Schema({
4 title: {
5 type: String,
6 required: true,
7 },
8 description: String,
9 status: {
10 type: String,
11 enum: ['active', 'inactive'],
12 },
13 title: {
14 type: Date,
15 default: Date.now(),
16 }
17});