const mongoose = require("mongoose"); const Schema = mongoose.Schema; const CommentSchema = new Schema({ date: { type: Date, required: true }, text: { type: String, required: true }, author: { type: String, required: true }, post: { type: mongoose.ObjectId, required: true }, _id: { type: mongoose.ObjectId, required: true }, password: { type: String, required: true }, }); // Virtual for comment RESTful functions CommentSchema.virtual("url").get(function () { // We don't use an arrow function as we'll need the this object return `/api/${post}/${this._id}`; }); // Export model module.exports = mongoose.model("Comment", CommentSchema);