Something went wrong. Try again.
VueTube is a YouTube clone built with nodejs, expressjs & mongodb. This is the RESTful API repository.
Something went wrong. Try again.
754 B · 35 lines
JavaScript
at master
123456789101112131415161718192021222324252627282930313233343536const mongoose = require('mongoose')
const Schema = mongoose.Schema
const CommentSchema = new Schema( { text: { type: String, minlength: [3, 'Must be three characters long'], required: [true, 'Text is required'] }, videoId: { type: mongoose.Schema.ObjectId, ref: 'Video', required: true }, userId: { type: mongoose.Schema.ObjectId, ref: 'User', required: true } }, { toJSON: { virtuals: true }, toObject: { virtuals: true }, timestamps: true })
CommentSchema.virtual('replies', { ref: 'Reply', localField: '_id', foreignField: 'commentId', justOne: false,
options: { sort: { createdAt: -1 } }})
module.exports = mongoose.model('Comment', CommentSchema)