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.
1.4 kB · 72 lines
JavaScript
at master
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273const mongoose = require('mongoose')
const Schema = mongoose.Schema
const VideoSchema = new Schema( { title: { type: String, minlength: [3, 'Must be three characters long'] }, description: { type: String, default: '' }, thumbnailUrl: { type: String, default: 'no-photo.jpg' }, views: { type: Number, default: 0 }, url: { type: String }, status: { type: String, enum: ['draft', 'private', 'public'], default: 'draft' }, categoryId: { type: mongoose.Schema.ObjectId, ref: 'Category' }, userId: { type: mongoose.Schema.ObjectId, ref: 'User', required: true } }, { toJSON: { virtuals: true }, toObject: { virtuals: true }, timestamps: true })
VideoSchema.index({ title: 'text' })
VideoSchema.virtual('dislikes', { ref: 'Feeling', localField: '_id', foreignField: 'videoId', justOne: false, count: true, match: { type: 'dislike' }})
VideoSchema.virtual('likes', { ref: 'Feeling', localField: '_id', foreignField: 'videoId', justOne: false, count: true, match: { type: 'like' }})
VideoSchema.virtual('comments', { ref: 'Comment', localField: '_id', foreignField: 'videoId', justOne: false, count: true})
module.exports = mongoose.model('Video', VideoSchema)