Book-template.js
js1 kB48 linesIn Lab2.zip
Lab2.zipmodelsBook-template.js
// models/Book-template.js
// Fill in the TODO sections to create the Book model
// This covers Chapter 7: MongoDB + Mongoose
const mongoose = require('mongoose');
// TODO 1: Create the Book schema
// Define all required fields with their types and validation
// const bookSchema = new mongoose.Schema({
// // TODO: Add title field
// // title: {
// // type: String,
// // required: [true, 'Title is required']
// // },
//
// // TODO: Add author field (String, required)
// // author: {
// // type: ???,
// // required: ???
// // },
//
// // TODO: Add category field (String, required)
// // Examples: 'fiction', 'non-fiction', 'science', 'history'
// // category: {
// // type: ???,
// // required: ???
// // },
//
// // TODO: Add price field (Number, required, minimum 0)
// // price: {
// // type: ???,
// // required: ???,
// // min: [0, 'Price cannot be negative']
// // },
//
// // TODO: Add inStock field (Boolean, default: true)
// // inStock: {
// // type: ???,
// // default: ???
// // }
// }, {
// // TODO 2: Enable timestamps (adds createdAt and updatedAt automatically)
// // timestamps: ???
// });
// TODO 3: Create and export the Book model
// Use mongoose.model('Book', bookSchema)
// module.exports = ???;