Generate a unique slug for mongoose.
npm i --save slugify-mongoose
const slugify = require('slugify-mongoose')
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const mySchema = new Schema({
title: { type: String },
slug: { type: String, slug: 'title', unique: true },
})
mySchema.plugin(slugify)
There are currently a lot of plugins for mongoose that already generate slugs, I made this because none of them worked with the web framework feathers.
This plugin also works with keystone.