const LyricSchema = new Schema({ song: { type: Schema.Types.ObjectId, ref: 'song' }, likes: { type: Number, default: 0 }, content: { type: String } }); LyricSchema.statics.like = function(id) { const Lyric = mongoose.model('lyric'); return Lyric.findById(id) .then(lyric => { ++lyric.likes; return lyric.save(); }) } mongoose.model('lyric', LyricSchema);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter