The very first step is to define a good model
import mongoose from 'mongoose'
const CompletedSchema = new mongoose.Schema(
{
type: { type: String, enum: ['course', 'classroom'], required: true },
parentslug: { type: String, required: true },
slug: { type: String, required: true },
userid: { type: String, required: true }
},
{ collection: 'completed' }
)
CompletedSchema.index({ slug: 1, userid: 1 }, { unique: true })
const model = mongoose.model('Completed', CompletedSchema)
export default model