A Mongoose plugin that generates a slug on save.
npm install --save @nesive/mongoose-slugRequire the plugin and use Mongoose.Schema.plugin() to include it.
var Mongoose = require('mongoose');
var MongooseSlug = require('@nesive/mongoose-slug');
var ArticleSchema = new Mongoose.Schema({
  title: String,
  slug: String
});
ArticleSchema.plugin(MongooseSlug);- properties: Document properties that are used to generate the slug. Can be a single string, or an array of strings. Default is- title.
ArticleSchema.plugin(MongooseSlug, { properties: 'author' });
ArticleSchema.plugin(MongooseSlug, { properties: ['author', 'title'] });- slug: An object of rules to generate the slug.- mode: Set mode to- prettyor- rfc3986. Default is- pretty.
- replacement: Replace spaces with replacement.
- symbols: Replace unicode symbols or not.
- remove: Regex to remove characters.
- lower: Result in lower case.
- charmap: Replace special characters.
- multicharmap: Replace multi-characters.
 
ArticleSchema.plugin(MongooseSlug, { slug: { lower: true } });