Add a Model
Define a database schema
Model example
Here is a sample model that you can use as a start up
let mongoose = require("mongoose");
let schema = mongoose.Schema({
title: {
type: String,
required: [true, "title must be set"],
},
body: {
type: String,
},
category: {
lowercase: true,
type: String,
enum: ["technology", "information", "fashion"],
default: "technology",
},
updated: {
type: Date,
},
date: {
type: Date,
default: Date.now(),
},
});
schema.pre("save", async function (next) {
this.updated = new Date();
next();
});
let model = mongoose.model("blogModel", schema);
module.exports = model;
Docs reference
info
A more detailed model with virtual methods and model references can be located at
/docs/api-reference/Model.js
from the project root