There are two parts to make specific requirement for the data to be inserted.
const videoSchema = new mongoose.Schema({
title: {type: String, required: true, trim: true, maxLength:80 },
description: {type: String, required: true, trim: true, minLength: 20 },
createdAt: {type: Date, required: true, default: Date.now },
hashtags: [{type: String, trim: true}],
meta: {
views: {type: Number, default: 0, required: true},
rating: {type: Number, default: 0, required: true},
},
});
more requirements make the data more specific.
But there are similar requirements we can make in HTML. like min/max legnth for the text or number. Which should we use?
The Answer is BOTH.
The requirements we put on the HTML is for the users.
And also to protect the database.
https://localhost:4000/
app.use("/", globalRouter);
=> globalRouter.get("/", home);
export const home = async(req, res) => {
const videos = await Video.find({});
console.log(videos);
return res.render("home", { pageTitle: "Home", videos });
};