how to make schema mongoose code example
Example 1: mongoose schema
const mongoose = require("mongoose");
const UserScheme = mongoose.Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
date: {
type: Date,
default: Date.now(),
},
});
module.exports = mongoose.model("user", UserScheme);
Example 2: mongoose schema
const mongoose = require('mongoose');
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true
}
}, {
timestamps: true
})
const User = mongoose.model('User', UserSchema);
module.exports = User;