1/// model/User.js
2
3const mongoose = require("mongoose");
4
5const UserScheme = mongoose.Schema({
6 name: {
7 type: String,
8 required: true,
9 },
10 email: {
11 type: String,
12 required: true,
13 unique: true,
14 },
15 password: {
16 type: String,
17 required: true,
18 },
19 date: {
20 type: Date,
21 default: Date.now(),
22 },
23});
24
25module.exports = mongoose.model("user", UserScheme);
26
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;
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 });
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});