gatsby-pingbot/lib/schema.ts

24 lines
409 B
TypeScript

import { model, models, Schema } from "mongoose"
interface URL {
url: string
}
const schema = new Schema<URL>({
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>('URL', schema)
export = URLModel