25 lines
585 B
JavaScript
25 lines
585 B
JavaScript
const mongoose = require('mongoose')
|
|
const timestamp = require('mongoose-timestamp')
|
|
|
|
const postBookmarkSchema = new mongoose.Schema({
|
|
postId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Post',
|
|
required: true,
|
|
index: true,
|
|
},
|
|
userId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'User',
|
|
required: true,
|
|
index: true,
|
|
},
|
|
})
|
|
|
|
postBookmarkSchema.index({ postId: 1, userId: 1 }, { unique: true })
|
|
|
|
postBookmarkSchema.plugin(timestamp)
|
|
const PostBookmarkModel = mongoose.model('PostBookmark', postBookmarkSchema)
|
|
|
|
module.exports = PostBookmarkModel
|