import { model, models, Schema } from "mongoose" interface URL { url: string } const schema = new Schema({ url: { type: String, required: true, unique: true } }) schema.path('url').validate(async function(value) { const count = await models.URL.countDocuments({ url: value }) return !count }, 'URL already exists') const URLModel = model('url', schema) export = URLModel