const { ObjectId } = require("mongoose"); const mongoose = require("mongoose"); const Schema = mongoose.Schema; const ItemSchema = new Schema({ name: { type: String, required: true }, category: { type: ObjectId, required: true }, description: { type: String, required: true }, price: { type: Number, required: true }, quantity: { type: Number, required: true }, }); // Virtual for author's URL ItemSchema.virtual("url").get(function () { // We don't use an arrow function as we'll need the this object return `/${this.category.simpleName}/${this._id}}`; }); // Export model module.exports = mongoose.model("Item", ItemSchema);